bitcrowd / chromic_pdf

Convenient HTML to PDF/A rendering library for Elixir based on Chrome & Ghostscript
Apache License 2.0
423 stars 38 forks source link

Define screen width when using `capture_screenshot/2` #319

Closed RodolfoSilva closed 3 months ago

RodolfoSilva commented 4 months ago

Hi guys,

I need to know if it is possible and how I can set the page size to take a screenshot. Right now, capture_screenshot/2 does not have an example of how we can define the screen widget.

RodolfoSilva commented 4 months ago

Right now, the workaround I've found is to set a global window size with:

chrome_args: "--window-size=375,375"

I was wondering if there is a better way to achieve this result without setting a global value. @maltoe do you have any suggestion?

maltoe commented 4 months ago

Hi @RodolfoSilva,

no, there's no option to set the screen size per job. The full_page option comes close, setting the screen size to the content size, see here. If you'd like to give it a try, you could start from there. Option could be something like {:device_metrics_override, [width: ..., height: ...]}.

maltoe commented 4 months ago

@RodolfoSilva I've pushed a PR that allows to more easily run custom protocols - something I've been wanting to do for a while. A custom protocol would allow you to execute whatever devtools commands you want before the actual PDF printing. I've included an example for your use-case in the tests :point_up:. As stated in the PR description, I'd consider the Protocol behaviour & the macros still to be internal API, but it's unlikely they're going to change anytime soon.

Still open for a :device_metrics_override option if you're willing to work on that instead, though.

RodolfoSilva commented 3 months ago

Thanks @maltoe, this solves my issue

maltoe commented 3 months ago

Released as v1.17