Search code examples
qtprintingqt5qt5.5qt5.6

Print HTML/contents of a webpage with Qt 5.5 or 5.6


With Qt 5.5 QWebEngine was introduced which will replace QWebKit. With Qt 5.6 (LTS) QWebKit is removed so that users have to use QWebEngine. Migration is quite easy except one thing: printing of webpages. This is not implemented and they hope to have it in Qt 5.7 (but perhaps even later). In other words: a mandatory function of Qt has ben removed without offering an replacement.

So my question: how can one print HTML/webpage content in recent versions of Qt?

  • QTextDocument as container for HTML content could be used for printing but is way too limited
  • QWebEngine does not offer a printing function
  • doing a QWebEngineView->render(&printer) is a poor workaround because it prints only the visible part of the shown page (also when the page is much larger than the screen)

Is there a possibility in Qt one can recommend? Or any other (slim) tools that can be used for this and which support images, tables and CSS layouts?

Any idea and suggestion is welcome!


Solution

  • With a lot of pricking Qt-support I did not found a solution but can update the state:

    QWebKit is gone but from their current plans it will not be removed in Qt 5.6. Since printing function of QWebEngine will be available earliest with Qt 5.7, they will keep QWebKit in their source package.

    But: it will be available as source only, so one has to compile it manually to use it. More funny: the guys from Qt are not sure about QWebKit itself. One says, sources will be available but with no guarantee it compiles and works with newer versions, an other one says, it will stay compilable as long as it is packaged (see comments at http://blog.qt.io/blog/2015/12/18/qt-5-6-beta-released/ )