views:

79

answers:

1

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!

A: 

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?

kizzx2