Failing to set margins when printing to pdf
-
I am using Qt 5.7 + Ubuntu 16.06 64 bits. After I load a page using QWebEnginePage I try to invoke the printToPdf method of QebEnginePage (link text). One of the arguments is a PageLayout and one of the arguments to create a PageLayout is the margin:
QPageLayout( QPageSize( QPageSize::A4 ), QPageLayout::Portrait, QMarginsF())
In my case I am using
QPageLayout( QPageSize( QPageSize::A4 ), QPageLayout::Portrait, QMarginsF(0,0,0,0))
But any value that I am passing to the pageloyut is ignored in the generated PDF.
The single way to workaround I found is to set up the following in CSS@page{ margin: 0; }
Is there any way to specify a margin via C++ code?
-
Did you try this function of QPrinter ?
http://doc.qt.io/qt-5/qprinter.html#setPageMargins