Additional options to print to pdf using chrome headless options

Viewed 2998

I am using the command line in Windows to print a PDF using Google Chrome with the headless options Print to PDF. I want to know how can I use the other options available as the margins and pages size or even orientation. I notice the options are available in https://chromedevtools.github.io/devtools-protocol/tot/Page#method-printToPDF

but base on this question, it seems doesnt work https://superuser.com/questions/1281309/how-can-i-print-a-webpage-in-landscape-mode-using-headless-chromium-on-the-comma

Has anyone use any of the options available and what is the correct sintaxis as the code below generates the pdf but ignores page size?

chrome.exe --headless --disable-gpu --print-to-pdf=C:\\Spotfire_Export\\'+filename+'.pdf --paperWidth=15 '+tempFolder+filename+'.html
1 Answers

I also had the same issue and found the same links mentioned before.

I'm generating pages with PHP and running google-chrome via exec.

Then I found this page and tried on my case and it worked well.

Here is the code which I added in my CSS.

@page {
    size: A4 landscape;
    margin: 0;
}

I hope that this helps someone.

Related