News for hackers. Stuff that matters.
Re:Headless mode in Firefox by randlet on Wednesday August 30, 2017 @09:15AM (#15131840)
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-c...
Re:Headless mode in Firefox by developer2 on Thursday August 31, 2017 @03:46AM (#15138802)
Any 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.

Re:Headless mode in Firefox by zimpenfish on Friday September 01, 2017 @04:57AM (#15147072)
Amusingly, 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.)

Re:Headless mode in Firefox by Sacho on Friday September 01, 2017 @04:50AM (#15147044)
I 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.
Re:Headless mode in Firefox by developer2 on Monday September 04, 2017 @10:41AM (#15168507)
The 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.
Re:Headless mode in Firefox by randlet on Thursday August 31, 2017 @12:07PM (#15141278)
That'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.
Re:Headless mode in Firefox by bartread on Wednesday August 30, 2017 @09:57AM (#15132156)
Wow - thanks for posting that: could come in handy on the project I'm currently working on!
Re:Headless mode in Firefox by newhere420 on Wednesday August 30, 2017 @11:13AM (#15132795)
We'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.

Re:Headless mode in Firefox by reagan83 on Wednesday August 30, 2017 @12:00PM (#15133258)
Can you elaborate on some of the issues you're having in the Chrome Remote Interface?
Re:Headless mode in Firefox by bartread on Wednesday August 30, 2017 @04:53PM (#15135906)
Yeah, 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.
Re:Headless mode in Firefox by kuschku on Thursday August 31, 2017 @11:56AM (#15141175)
You can use inkscape’s CLI interface to get SVG from pdf, and then manipulate that with any XML editing library automatically
Re:Headless mode in Firefox by perryprog on Wednesday August 30, 2017 @12:39PM (#15133596)
Is this open source? It would be very interesting to take a look at!
Re:Headless mode in Firefox by megous on Wednesday August 30, 2017 @10:47AM (#15132519)
If only browsers supported creation of page headers and footers.
Re:Headless mode in Firefox by addedlovely on Wednesday August 30, 2017 @12:27PM (#15133485)
@page { @top-center { content: element(pageHeader); } } #pageHeader{ position: running(pageHeader); }

http://www.w3.org/TR/css3-gcpm/#running-elements

Re:Headless mode in Firefox by underbluewaters on Wednesday August 30, 2017 @12:47PM (#15133683)
Thank you for this. I've been doing this so wrong for a long time.
Re:Headless mode in Firefox by dflock on Wednesday August 30, 2017 @12:49PM (#15133701)
True - 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.
Re:Headless mode in Firefox by reagan83 on Wednesday August 30, 2017 @11:53AM (#15133174)
I 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.