开发者

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

开发者 https://www.devze.com 2023-01-02 00:34 出处:网络
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?

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 vecto开发者_高级运维r graphic dump?

Thanks a lot for any guidance!


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消