I am using the CLI for Google Chrome to save an HTML to PDF. I need tp save the PDF in landscape mode, cannot find the command. I am using this command:
google-chrome --headless --disable-gpu --run-all-compositor-stages-before-draw --print-to-pdf-no-header --Landscape=true --print-to-pdf="MyPdf.pdf" "MyHtml.html"
CodePudding user response:
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}.
2021/2? best option is possibly an enabler like https://github.com/dataverity/chromehtml2pdf#readme