Another method I haven't seen mentioned yet and that I grew fond of is to use Apache FOP ("Formatting Object Processor") which is still under active development and comes with this beautifully retro Apache open source homepages[0]:
(1) It has a pretty good idea about Layouts, Pages and other elements one would need for printing
(2) It supported all the graphics formats that I ever needed in the past and automatically fetches images by URL when it stumbles upon them.
(3) It is easily embeddable into some custom Java app.
(4) It is based on W3C open standard (which though doesn't seem to be developed anymore)
(5) It does PDF/A.
(6) XML/XSLT is a bit annoying to write for your template, so I used a common templating engine (e.g. Thymeleaf) to render the XML/XSLT that I passed on to FOP. Worked like a breeze and gives you the possibility to create your own little DSL.
(7) I'm still happily generating my invoices through FOP put behind an API that takes input data and uploads the generated documents into a bucket.
(8) I don't have the exact numbers but last time I checked and compared output sizes of browser printed pdfs vs "generated by Fop", I saw smaller PDFs with Fop. It doesn't mangle the input images though
All in all, I trust FOP better to generate printable documents than any CSS/Headless Browser thing. It comes with an arcane template format which, as said, can be abstracted away but therefore has much smaller infrastructure footprint than spawning headless browsers.
(1) It has a pretty good idea about Layouts, Pages and other elements one would need for printing
(2) It supported all the graphics formats that I ever needed in the past and automatically fetches images by URL when it stumbles upon them.
(3) It is easily embeddable into some custom Java app.
(4) It is based on W3C open standard (which though doesn't seem to be developed anymore)
(5) It does PDF/A.
(6) XML/XSLT is a bit annoying to write for your template, so I used a common templating engine (e.g. Thymeleaf) to render the XML/XSLT that I passed on to FOP. Worked like a breeze and gives you the possibility to create your own little DSL.
(7) I'm still happily generating my invoices through FOP put behind an API that takes input data and uploads the generated documents into a bucket.
(8) I don't have the exact numbers but last time I checked and compared output sizes of browser printed pdfs vs "generated by Fop", I saw smaller PDFs with Fop. It doesn't mangle the input images though
All in all, I trust FOP better to generate printable documents than any CSS/Headless Browser thing. It comes with an arcane template format which, as said, can be abstracted away but therefore has much smaller infrastructure footprint than spawning headless browsers.
[0] https://xmlgraphics.apache.org/