[Interest] QtWebEngine: printing a webpage invoked by the javascript window.print() function

Jason Dolan jason at pcc.com
Mon Oct 19 17:56:19 CEST 2015


Hi guys,

I posted this on stackoverflow(http://stackoverflow.com/questions/33217930/qtwebengine-printing-a-webpage-invoked-by-javascript <http://stackoverflow.com/questions/33217930/qtwebengine-printing-a-webpage-invoked-by-javascript>), but then it occurred to me that I probably should have posted it here first.

I’m porting a project from Qt4.8.6 to Qt5.5.1.  In doing so, we are hoping to upgrade from QtWebkit to QtWebEngine.  I am slowly going through the list of things that need to be done to allow that port to happen.  My current subject of interest is printing.

Looking here (https://trello.com/c/JE5kosmC/72-printing-support <https://trello.com/c/JE5kosmC/72-printing-support>) it seems like official printing support for QtWebEngine won’t come until Qt5.7.  Luckily it appears like there are options until then.

From here (http://stackoverflow.com/questions/32711901/qwebengine-print-a-page <http://stackoverflow.com/questions/32711901/qwebengine-print-a-page>), I know that I can use QWebEngineView::render, passing in a pointer to my QPrinter object to programmatically print a web page.

But if the print request was invoked by javascript (from the window.print() javascript function for instance), I don't know how to catch that request to then hand off to my print function.

I found this (http://tjvantoll.com/2012/06/15/detecting-print-requests-with-javascript/ <http://tjvantoll.com/2012/06/15/detecting-print-requests-with-javascript/>) which apparently allows you to call another javascript function when the print function is invoked.  Perhaps I can somehow inject this javascript into the page and use it somehow with QWebChannel (a completely new class to me) to catch the javascript print command and relay it to my c++ print function?

Or perhaps I’m completely barking up the wrong tree.

Does anyone have any thoughts?

--
Jason Dolan
Software Developer
PCC
Control Your Future.

800-722-7708
jason at pcc.com <mailto:jason at pcc.com>
www.pcc.com <http://www.pcc.com/>
twitter.com/pccvt



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20151019/806c3771/attachment.html>


More information about the Interest mailing list