Important: Please read the Qt Code of Conduct -

Export QWebPage to PDF. Output too small.

  • I am trying to export a QWebPage as PDF file. It works so far, but the output in the pdf is too small.
    It looks like the webkit scales down the content when it is converted.
    The border of the div in the HTML content should span a width of 210mm (826px) and a height of 297mm. On the generated pdf the border doest not fill the entire page. There is a space of ~40mm in width and ~63mm in height on the left and bottom side of the page. So i think the html content is scaled down.

    Does someone has a idea why this is done?

    My code looks like

        QWebPage *page=new QWebPage();
        page->mainFrame()->setHtml("<html><head></head><body><div style=\"width: 826px; height: 297mm; font-size: 12pt; border: 1px solid #000;\">{TITLE}<br><br>Text: {TEST}<br>Integer: {INTEGER}<br>Decimal: {DEC}</br>Dummy: {DUMMY}<br>Table: <table border=\"1\">{TABLE}</table></div></body></html>");
        QPrinter printer(QPrinter::HighResolution);
        printer.setPageMargins(0, 0, 0, 0, QPrinter::Millimeter);

  • Moderators

    i don't know what happens internally in QtWebkit when printing.
    But i would try to render the webpage to a QPixmap first - using QWebFrame::render() - and then print this image. This might give you more control afterall.

Log in to reply