Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Qt, can I QWebFrame::print() supply additional rendering layers?

I am leveraging WebKit from QWebFrame to convert HTML pages to PDF. Is it possible to apply some additional rendering logic before the page is sent to the QPrinter?

What I want to do is to be able to convert links and form controls in HTML to interactive counterparts in PDF, instead of just a vector graphic dump?

Thanks a lot for any guidance!

like image 793
kizzx2 Avatar asked Nov 14 '22 10:11

kizzx2


1 Answers

I found a possible solution using QWebFrame::renderTreeDump() and QWebFrame::findAllElements() (new in Qt 4.6).

It doesn't quite "supply additional rendering layers," but accomplishes what I want to do: I call findAllElements() to scrape the DOM tree, apply any logic I want by setting the HTML element's attributes.

For more complicated operations, such as replacing form controls with my own rendering process, I need to scrape both the DOM tree and the render tree, tinker with the DOM tree so the element doesn't get sent to QPrinter. In the end, I scrape the resulting PDF file, inject my own rendered for controls using the information I obtained from the render tree and the DOM tree.

This feels unnecessarily complicated. Does anyone has a more elegant solution to this problem?

like image 101
kizzx2 Avatar answered Dec 24 '22 00:12

kizzx2