Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    How can I print a QWebPage to a QPdfWriter?

    Qt WebKit
    1
    1
    578
    Loading More Posts
    • 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.
    • ricokahler
      ricokahler last edited by ricokahler

      Problem: I can't create multi-paged PDF documents from QWebFrame with QPdfWriter because there is no ::print() method that takes a QPagedDevice or QPdfWriter (or at least I think that's the reason)

      (context: this is for: https://github.com/ariya/phantomjs/issues/14268)

      This method is from the webpage module from PhantomJS.

      bool WebPage::renderPdf(QPdfWriter& pdfWriter)
      {
          // code removed for brevity
      
          QPainter painter(&pdfWriter);
          //m_mainFrame->render(&painter);
          QRect pageRect = pdfWriter.pageLayout().pageSize().rectPoints();
          // ===============================
          // How do I include QtPrintContext
          // ===============================
          QtPrintContext printContext(&painter, pageRect, m_mainFrame->d);
      
          for (int page = 0; page < printContext.pageCount(); page++) {
              printContext.spoolPage(page, pageRect.width());
              pdfWriter.newPage();
          }
          painter.end();
      
          return true;
      }
      

      Question: How can I #include QtPrintContext in the module above? Will this even fix the problem?

      Thanks!

      1 Reply Last reply Reply Quote 0
      • First post
        Last post