How to Change Paper Size in Headless Chrome - Print-To-Pdf

Chrome: How to print PDF with original size (100%, no scaling/shrinking)

This is my test results from what i have seen by using a windows system and a Mac ( Yosemite )

Windows :

Printed the PDF in Chome : Perfect - 213 mm

Printed in IE : Perfect - 213 mm. This was less before ( around 205-210ish ). So changed the default print settings :

Selected the Print option -> Used Print Dialog -> Selected the printer -> Print Preferences -> Advanced -> Paper Size -> Changed scaling manually -> tested A4, A5 and so on.-> A5 ( for some reason gave me 213 )

So i moved onto the Mac.

Mac Findings:

Changed Paper Size and tested the same : Size was 213 mm.

This was done like this : Apple Print

So naturally, i tested printing it through Chrome directly instead of opening the PDF through OSX -> Printed at 205 mm.

Tested with printscaling on prawn at :appdefault -> Printed at 213 mm.

Tested the same on Firefox -> lower than 205 - 210 mm.

So i dont really know if its a Chrome issue because its acting weird on Firefox for me.

So ultimately, these are my findings after testing out the code on my end.

Chrome CLI save to PDF landscape

You can not use Landcape on command line for chrome or derivatives like Edge.

That is intentional as the developer team have certainly up to now, resisted expanding similar command line settings for such usage, their recommendation is you should be using API methods.

You can workaround that by using either @page html or by injected javascript or else the printer needs to define the page output.

2017

We don't intend to provide all the flexibility that DevTools provides through command line options: There are various technical reasons why command line options cannot provide the same flexibility.

It appears that Headless Chrome does parse @page as well to some extent, but behaves differently than the desktop version: If you specify @page {size}, headless seems to change the dimensions of the page box (essentially, the print area), and not the sheet, which always remains US Letter sized. However, it does rotate the sheet if you specify {size: landscape}.

The print options are exposed via the DevTools API only (and not via command line flags), see comments #51 and prior.

2021/2? best option is possibly an enabler like https://github.com/dataverity/chromehtml2pdf#readme



Related Topics



Leave a reply



Submit