Adding feature print-media-type
Hi. I'm using the wkhtmltopdf tool a while ago now. Because the html that I'm transforming to pdf has styling for screen and print views, i'm using the --print-media-type option to get the printing style, since the need is to have a "printed" version of the document. I am not seeing that option in your help. Is that option lacking or are there any plans to add it in a future version?
Many thanks for the great tool.
It's not supported yet, but that's certainly an interesting option to add if possible with CEF.
Just to be sure you're referring to something like this, and being able to choose between print and screen ?
<style>
div {
border: 1px solid black;
}
@media print {
div {
border: 1px dashed black;
font-size: 300%;
}
}
</style>
<div>Hello World</div>
Thanks for the reply. Yes... If it would help, I think I can provide you an HTML as an example. The documents I'm converting are medical documentation. The screen media type has some parts that are collapsed and moved from site. The printing part is showing everything and formatted in a popular/official way.
Many thanks for the support.
If you have one exemple and it's not confidential, please provide it, it may bring forward issues that do not exist on a more simplistic test case.
I did a a quick full text search on the CEF and web, and could not find an option, though Chrome supports such an option, so it could just be a matter of searching harder.
As a workaround, using the snippet at https://stackoverflow.com/questions/37080744/is-there-a-way-to-enable-media-print-css-to-a-normal-view with the --javascript option may work to force media print or media screen.
Array.prototype.forEach.call(document.getElementsByTagName('style'), function(style) {
style.innerText = style.innerText.replace(/@media print/gi, '@media screen');
});
It's just a regexp though, so it'll be vulnerable to all kinds of failures... but in a well define context, it could be good enough.
I can provide an example. They are of public domain, in a site that has no login whatsoever.
This file is a typical html file that I should convert to pdf and, currently, using wkhtmltopdf to do the job. If you, from your browser, print the file, you can get the style defined for print media type. That's the style i should use to generate the PDFs.
Many thanks by your efforts.
I tested with the html file you provided, and with a pdf output I got the "media print" version while the jpg output resulted in the "media screen" version.
Ar you after getting the "media screen" version for the pdf output, or the "media print" for the jpg version ? (both would be best I guess, but gotta start somwehere)
Hi. I'm always using the "media print", since I have to store a "printed" version of the document. There are several documents similar to that one, but the idea is always the same, i.e., get vision of the thing like if it was printed. I'm not using other types of output.
Therefore, it looks pretty fine like that. When you think you gonna create a definitive version for production?
Many thanks for your time on this.
No idea about the definitive version: it is going to chase the CEF PDF support, which as of CEF 89 appears broken in some way :/ Not sure yet if it's somewhere in CEF, Chromium or a wrapper somwhere.
Ok Eric.
Most appreciate the your work. Keep us updated with the news. Thanks a million!
Upstream issue https://bitbucket.org/chromiumembedded/cef/issues/3099/cefclient-printtopdf-not-working