How can I print a QWebPage to a QPdfWriter?

  • 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:

    This method is from the webpage module from PhantomJS.

    bool WebPage::renderPdf(QPdfWriter& pdfWriter)
        // code removed for brevity
        QPainter painter(&pdfWriter);
        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());
        return true;

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


Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.