chromium-browser --headless --disable-gpu --print-to-pdf=output_file_name.pdf file:///path/to/your/html
[1] https://developers.google.com/web/updates/2017/04/headless-c...It works very well, but there are some gotchas with regard to the Chrome Remoting Interface.
Capturing the PDF at even the onload event (let alone the useless DOMContentLoaded event) is going to capture an incomplete picture in a huge number of situations. Frankly, a PDF capture at onload event is going to be utterly unusable. Is there a way to set a delay before capturing, ie: 10 seconds?
In an ideal world, a true "finished loading" event would trigger only after all DOMContentLoaded and onload handlers are executed, only once any AJAX requests launched by such handlers are completed (including requests fired off in their handlers, recursively). Of course, websockets and long polling ajax would still interfere with detecting a true "finished" event, but it'd be better than setting an artificially large delay of 10+ seconds.
Except then it was just a case of "wait 30 seconds and pray" because there was none of this fanciness.
(bloody kids, get off my lawn, banging two rocks together, etc.)
The security issues don't apply in all circumstances, of course, but if you feel like taking a shortcut to PDF generation and printing through a headless browser, you need to keep them in mind.
I used this approach for a project at a previous company and not only did it keep the potentially unsafe external code execution isolated from the rest of the stack, but it also proved to be fantastically scalable because of the ability to have AWS Lambda running many headless browsers in parallel compared to trying to scale something like this out on your own hardware.
It also supports page-oriented CSS declarations and variables, like headers, footers, page numbers, etc.
Browsers are catching up on paged media options, but they're not all the way there yet. The rest of the stuff Prince does is not (and arguably shouldn't be) in the scope of headless Chrome.
There was a brief moment where headless Chrome supported flexbox in print before Prince did, but that was fixed a month or so ago in Prince dev and should land in production soon if it hasn't already.
Also it blisteringly fast. You'll process 10 documents before headless Chrome has even finished starting up.
There's a free trial which prints a watermark so you can give it a spin. very easy to get up and running, even has a GUI so that you can throw some test docs at it without any effort at all.
Stuff looks like it was created with QuarkXPress or Adobe InDesign.
To get better control of the print job, do you ever use Adobe InDesign?