Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QtWebEngine
  4. Problem(s) with QWebEnginePage to print an HTML document in PDF
Forum Updated to NodeBB v4.3 + New Features

Problem(s) with QWebEnginePage to print an HTML document in PDF

Scheduled Pinned Locked Moved Solved QtWebEngine
2 Posts 1 Posters 1.5k Views
  • 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.
  • A Offline
    A Offline
    Alain38
    wrote on last edited by
    #1

    Hi,
    I'm trying to move an application, initially written with Qt 4.8.4, to Qt 5.9. This application used QWebPage to create an HTML document and finally print it in PDF. The HMTL is given to the QWebPage by setHtml() because we are doing some changes inside before to print it.

    So, now I'm trying to use qWebEnginePage::printToPdf() to make the same stuff. But I encounter two problems:
    1- I have an abort in QtWebEnginProcessd.exe when the function is called. And, as it is an external process I cannot debug it to find the source. This is not critical because everything works well in release mode,

    2- The HTML documents contains a lot of images. Some of them use absolute paths (C:\my_path\img.png) because they correspond to static images (logo of the company). And some of them use relative paths because the are document specific, and must move we it (we move the whole directory). So, I have troubles with these images. They do not appear in the PDF file. I tried to set the current directory (before to call setHtml) to the document directory, but without change.

    So, is it possible to say to the QWebEnginePage a "current directory"?

    Thanks for your help.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Alain38
      wrote on last edited by
      #2

      OK,
      I finally found the solution. The trick was to use the second parameter of setHtml as follow:

                  m_currentPage->setHtml(htmlContent, QUrl(QString("file:///%1/").arg(QFileInfo(filename).absolutePath())));
      
      

      And the / after %1 is important, as QFileInfo::absolutePath does not add it

      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