Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding feature print-media-type #3

Open
ArturGomesSoft opened this issue Mar 11, 2021 · 9 comments
Open

Adding feature print-media-type #3

ArturGomesSoft opened this issue Mar 11, 2021 · 9 comments

Comments

@ArturGomesSoft
Copy link

ArturGomesSoft commented Mar 11, 2021

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.

@EricGrange
Copy link
Owner

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>

@ArturGomesSoft
Copy link
Author

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.

@EricGrange
Copy link
Owner

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.

@ArturGomesSoft
Copy link
Author

I can provide an example. They are of public domain, in a site that has no login whatsoever.

test1.zip

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.

@EricGrange
Copy link
Owner

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)

@ArturGomesSoft
Copy link
Author

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.

@EricGrange
Copy link
Owner

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.

@ArturGomesSoft
Copy link
Author

Ok Eric.

Most appreciate the your work.
Keep us updated with the news.
Thanks a million!

@EricGrange
Copy link
Owner

@EricGrange EricGrange changed the title Adding feature Adding feature print-media-type Mar 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants