Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-69222

QWebenginePage print resultCallback called before print finished.

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • 5.12
    • 5.10.1
    • GUI: Printing, WebEngine
    • None
    • Windows 7 x64 Ultimate.

      Visual Studio 2015 Enterprise Update 3.

      Prebuild Qt 5.10.0 from qt ftp server.
    • Windows
    • I1e6242627821d57f877b587c1d760fac16c97ae2

    Description

      I need to make shadow copy of printed document as pdf file. I want to do this in print's resultCallback.

       

      But i get an error:

      Cannot print to PDF while at the same time printing on printer Microsoft XPS Document Writer
      

      Example:

      #include <QApplication>
      #include <QCoreApplication>
      
      #include <QWebEngineView>
      #include <QWebEngineSettings>
      
      #include <QPrinter>
      #include <QPrintDialog>
      
      int main(int argc, char *argv[])
      {
        QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
        QApplication a(argc, argv);
      
        QPrinter printer;
      
        QWebEngineView* viewer = new QWebEngineView();
        viewer->settings()->setAttribute(QWebEngineSettings::PrintElementBackgrounds, true);
      
        QObject::connect(viewer->page(), &QWebEnginePage::loadFinished,
          [&](bool ok)
          {
            QPrintDialog printDialog(&printer);
            if (printDialog.exec() == QDialog::Accepted)
            {
              printer.setPaperSize(QPrinter::A4);
              printer.setPageOrientation(QPageLayout::Landscape);
              printer.setPageMargins(0, 0, 0, 0, QPrinter::Millimeter);
              printer.setFullPage(true);
               
              //print on printer
              viewer->page()->print(&printer,
                [&](bool result)
                {
                  //print to pdf
                  viewer->page()->printToPdf(QString("tmp.pdf"));
                });
            }
          });
      
        viewer->load(QUrl("http://google.com"));
        viewer->show();
      
        int result = a.exec();
      
        delete viewer;
      
        return result;
      }
      

      Attachments

        For Gerrit Dashboard: QTBUG-69222
        # Subject Branch Project Status CR V

        Activity

          People

            davidsz Szabolcs David
            seer SeeR
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes