I am using headless Chrome to export html documents to pdf
google-chrome --headless --disable-gpu --print-to-pdf='output_path' 'url'
How can I change paper size in generated pdf?
I have control on both Chrome parameters and html.
I always get US Letter.
There are no documented command-line options for this.
I've tried setting CSS: @page {size: A4;}
. No effect in headless mode, but works when I hit Ctrl+P in normal mode (option to choose paper size for Save as pdf
disappears, exported pdf has A4 page size).
I've tried this on Chrome versions 59, 60 and 61 on Ubuntu 16.04.
You can run headless chrome from Node environment.
Then you would be able to pass additional parameters to printToPdf
function including pageWidth
and pageHeight
.