Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Generating a PDF file from an HTML document
Alain38 last edited by
we are currently trying to generate a PDF file from an HTML document. For this, we are using the following code:
printer.setOutputFileName(m_projectPath + "/" + m_outFilename + ".pdf");
m_page->mainFrame()->print(&printer); // m_page is a QWebPage
The QWebPage m_page is created from an HTML template document (written by hand) containing CSS rules. As we need that the document be divided in 4 pages this template is of the form:
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="description" content="test de presence d'une description">
<!-- ============================================== css style ============================================= -->
<!-- ============================================== head / body ============================================== -->
Stuff for the first page...
<!-- =============== page 2 =============- -->
Stuff for the second page...
.. and so on for the two other pages...
As we are using Qt 4.8.4 we cannot put "page break" between the pages (as Qt does not manage them as found as bug in numerous posts on Internet). It is why we are specifying a fixed height for the "page div". And this part is very strange. On my computer (under Windows 8.1) I must specify an height of 36.2cm to be able to have the right printing on a A4 page (i.e. a normal height of 29.7cm). On another computer (under Windows 7), I must specify an height of 30.6cm.
Does somebody has an idea of the origin of the problem, and the way to solve it?