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

Pdf rendering very slow using Qt Pdf module

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • 6.2.5, 6.4.0 Beta1
    • 6.3.0 RC
    • PDF
    • None
    • Windows 11
    • Windows
    • 165bc962e8 (qt/qtwebengine/dev) d379ee8735 (qt/qtwebengine/6.2) d379ee8735 (qt/tqtc-qtwebengine/6.2) 165bc962e8 (qt/tqtc-qtwebengine/dev) 165bc962e8 (qt/qtwebengine/6.4) 165bc962e8 (qt/tqtc-qtwebengine/6.4) c22aa3deb8 (qt/qtwebengine/6.3)

    Description

      I've been experimenting with the Qt Pdf module to render some pdf files. However, some pdf files are very slowly processed. For example running this code:

      int main(int argc, char *argv[])
      {
          QPdfDocument pdfDocument;
          pdfDocument.load("test3.pdf");
      
          QElapsedTimer timer;
          timer.start();
      
          auto image = pdfDocument.render(0, QSize(1000, 1000));
          image.save("testimage.png");
      
          qDebug () << QString("PDF RENDERED IN %1 ms").arg(timer.elapsed());
      }
      

      Against this pdf filetest3.pdfUnable to embed resource: test3.pdf of type application/pdf

      shows  that the rendering time for the first page to a 1000x1000 QImage is around 2000ms.

      Investigating this further, I decided to use pdfium directly and the following code:

       

      int main(int argc, char *argv[])
      {
          // initialise pdfium and ...
      
          FPDF_DOCUMENT doc = FPDF_LoadDocument("test3.pdf", NULL);
      
          QElapsedTimer timer;
          timer.start();
      
          if(!doc){
              qCritical() << "Cannot render page for invalid document";
          }
          FPDF_PAGE pdfPage = FPDF_LoadPage(doc, 0);
          if(!pdfPage){
              qCritical() << "Cannot render page because failed to load";
          }
      
          QImage result(QSize(1000, 1000), QImage::Format_ARGB32);
          result.fill(Qt::transparent);
          FPDF_BITMAP bitmap = FPDFBitmap_CreateEx(result.width(), result.height(), FPDFBitmap_BGRA, result.bits(), result.bytesPerLine());
          FPDF_RenderPageBitmap(bitmap, pdfPage, 0, 0, result.width(), result.height(), 0, 0);
      
          FPDF_ClosePage(pdfPage);
      
          result.save("testimage.png");
          
          qDebug () << QString("PDF RENDERED IN %1 ms").arg(timer.elapsed());
      }
      

      gives a render time of less than 500ms, which is very strange as the code is pretty much the same as Qt Pdf module [here](https://github.com/qt/qtwebengine/blob/dev/src/pdf/qpdfdocument.cpp#L753). I've also tested the [multipage example](https://github.com/qt/qtwebengine/tree/dev/examples/pdf/multipage) included in the source of QtWebengine and enabling qt.pdf.document=true logs shows similarly high render times.

       

      Attachments

        1. timeline-init.png
          timeline-init.png
          94 kB
        2. timeline.png
          timeline.png
          117 kB
        3. test3.pdf
          1.51 MB
        4. pdfiumtest.zip
          4.98 MB
        5. fpdf.tgz
          1 kB
        6. flamegraph.png
          flamegraph.png
          199 kB

        Activity

          People

            srutledg Shawn Rutledge
            daljit97 Daljit Singh
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: