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



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



  • 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


Log in to reply
 

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