Print HTML content
-
Hi
I try to print HTML content combined with inline CSS.
-
If I print QWebview directly, render is OK (i.e. CSS display:block renders correctly)
@view->print(printer);@ -
If I print just part of doc. using QTextDocument
@QTextDocument htmlDocument = frame->findFirstElement("#qtprint");
htmlDocument.print(printer);@
Correct me if I'm wrong, I think this is due to "RichText limitations":https://qt-project.org/doc/qt-4.8/richtext-html-subset.html#css-properties
=> css "display" not supported
=> How to use "QWebview rendering" just for a part of HTML?@<body>
....
<div id="qtprint">
<style type="text/css">
.mystyle { display:block; height:200px; background:#800000; color:#FFF; padding:2px 5px; }
</style>
<span class="mystyle">Test</span>
</div>
......
</body>@NB: the only solution I found is to use view->print(printer); with specific print CSS file to hide everything except the DIV #qtprint
=> i.e. div { display:none; } + div#qtprint { display:block; }
But it would be better and safer to load & print only the necessary code -