Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt WebKit
  4. Export QWebPage to PDF. Output too small.
Forum Updated to NodeBB v4.3 + New Features

Export QWebPage to PDF. Output too small.

Scheduled Pinned Locked Moved Unsolved Qt WebKit
2 Posts 2 Posters 1.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    PhTe
    wrote on last edited by
    #1

    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.setResolution(100);
        printer.setOutputFormat(QPrinter::PdfFormat);
        printer.setPageMargins(0, 0, 0, 0, QPrinter::Millimeter);
        printer.setOutputFileName(path);
        printer.setPageSize(QPrinter::A4);
        printer.setPrintRange(QPrinter::AllPages);
    
        page->mainFrame()->print(&printer);
    
    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      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.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved