4 ms·
You can generate pdfs with headless Chromium/Chrome pretty easily[1]. chromium-browser --headless --disable-gpu --print-to-pdf=output_file_name.pdf file://
by randlet 9y ago
You can generate pdfs with headless Chromium/Chrome pretty easily[1].
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-chrome#create_a_pdf_dom https://developers.google.com/web/updates/2017/04/headless-c...
- bartread 9y agoWow - thanks for posting that: could come in handy on the project I'm currently working on!
- newhere420 9y agoWe're using Chrome Headless inside Docker to produce thousands of PDF reports from an Angular/D3 web app. It works very well, but there are some gotchas with regard to the Chrome Remoting Interface.
- reagan83 9y agoCan you elaborate on some of the issues you're having in the Chrome Remote Interface?
- perryprog 9y agoIs this open source? It would be very interesting to take a look at!
- bartread 9y agoYeah, D3 is what we're working with as well; also need to be able to embed the charts in Powerpoint, but that'll be a different story. All fun and games.
- kuschku 9y agoYou can use inkscape’s CLI interface to get SVG from pdf, and then manipulate that with any XML editing library automatically
- megous 9y agoIf only browsers supported creation of page headers and footers.
- deleted 9y ago[deleted]
- addedlovely 9y ago@page { @top-center { content: element(pageHeader); } } #pageHeader{ position: running(pageHeader); } http://www.w3.org/TR/css3-gcpm/#running-elements http://www.w3.org/TR/css3-gcpm/#running-elements
- underbluewaters 9y agoThank you for this. I've been doing this so wrong for a long time.
- dflock 9y agoTrue - but you can get them to output to PDF, then composite/stamp this pdf onto a PDF with headers/footers/whatever on it. This is very easy to do with pdftk.
- reagan83 9y agoI built a simple REST API that wraps this call for my other projects and it's been working great the past few months. If this would be useful to you my contact info is in my profile.
- developer2 9y agoAny idea when exactly the PDF capture is performed? So many pages now render a minimal initial load, while the actual content is greatly delayed (usually < 100ms, but sometimes 3+ seconds) due to being loaded from one or more AJAX sources. 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.
- randlet 9y agoThat's a good question but I don't know the answer. The reports we generate don't use js so I've never needed to investigate.
- Sacho 9y agoI don't think this feature is "utterly unusable". You can run your JS, wait for whatever events you want, and then pipe the resulting HTML to a --print-to-pdf command.
- developer2 9y agoThe primary reason to print a pdf would be to do so to any random 3rd party page. Sadly, you have no control over how 3rd party sites render/load their content. And --print-to-pdf likely captures the render of the page at some predetermined point, my guess being the "onload" event. Which, again, is not going to result in a fully rendered page for many sites that load in their primary content using AJAX.
- zimpenfish 9y agoAmusingly, I had this same problem back in ~1999 when trying to automatically screen capture webpages with Netscape on X. 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.)