News for hackers. Stuff that matters.
Re:Chrome 59 has cross-platform headless support by masterleep on Wednesday April 12, 2017 @06:17PM (#14102248)
Please let this be capable of generating PDFs from HTML from the command line.
Re:Chrome 59 has cross-platform headless support by vvoyer on Wednesday April 12, 2017 @06:32PM (#14102350)
Re:Chrome 59 has cross-platform headless support by jzfeng on Thursday April 13, 2017 @12:13AM (#14104113)
The print to pdf command currently only support default print settings. Adding support for customized page size, header and footer, dpi, etc. is in progress.

Please see bug: https://bugs.chromium.org/p/chromium/issues/detail?id=603559 for updates.

Re:Chrome 59 has cross-platform headless support by masterleep on Thursday April 13, 2017 @12:46AM (#14104240)
Excellent news, thanks!
Re:Chrome 59 has cross-platform headless support by erikig on Wednesday April 12, 2017 @09:01PM (#14103192)
https://wkhtmltopdf.org/

You can download the two tools wkhtmltopdf and wkhtmltoimage which use WebKit to generate pdfs/images.

Re:Chrome 59 has cross-platform headless support by ashkulz on Thursday April 13, 2017 @12:14AM (#14104116)
I'm the maintainer of wkhtmltopdf, and it's hopelessly out of date. There's still some bugs in the Chrome print-to-PDF support as support was added just a few days ago:

https://bugs.chromium.org/p/chromium/issues/detail?id=603559

Not sure if all the full functionality that wkhtmltopdf can be ported, it had patches to Qt/WebKit to enable that ... probably will need API enhancements in Chrome. Don't have the time right now, but I registered http://crhtmltopdf.org a while ago hoping that I'd get around to it.

Re:Chrome 59 has cross-platform headless support by adam77 on Wednesday April 12, 2017 @10:33PM (#14103672)
Sadly wkhtmltopdf's version of Webkit is ancient :( No flexbox, no es6, etc...
Re:Chrome 59 has cross-platform headless support by codedokode on Thursday April 13, 2017 @06:17AM (#14105583)
I think it just means that the site is poorly designed. I think websites should work correctly everywhere where CSS2.1 and ES3 is supported. Otherwise some users won't be able to view those sites.
Re:Chrome 59 has cross-platform headless support by Derbasti on Thursday April 13, 2017 @12:12AM (#14104112)
No paged media makes page formatting much too painful.
Re:Chrome 59 has cross-platform headless support by michael_miller on Wednesday April 12, 2017 @06:49PM (#14102474)
Any idea if you can configure the page DPI with this API?
Re:Chrome 59 has cross-platform headless support by kenshaw on Wednesday April 12, 2017 @07:19PM (#14102643)
Yes, the emulation domain has APIs for changing that.
Re:Chrome 59 has cross-platform headless support by mixu on Wednesday April 12, 2017 @07:42PM (#14102777)
If you're willing to wait until Electron releases a Chrome 59 -based build, I'll be updating https://github.com/mixu/electroshot which handles screenshots and print-to-PDF along with a bunch of other niceties.
Re:Chrome 59 has cross-platform headless support by Derbasti on Thursday April 13, 2017 @12:11AM (#14104107)
Does it support paged media?
Re:Chrome 59 has cross-platform headless support by pizza on Wednesday April 12, 2017 @06:55PM (#14102515)
Is there an easy way to do the opposite? e.g. read PDFs as HTML (intended to be read through a remote shell), or text?
Re:Chrome 59 has cross-platform headless support by kccqzy on Wednesday April 12, 2017 @07:18PM (#14102630)
Extracting text from PDF is not hard, though PDF only contains low-level formatting instructions so the result might not be nice, especially if the original PDF has any non-trivial formatting, like pull quotes, multi-column text, etc. If you don't care about that or the correct "flow" of text, it should be easy enough to just find all the Tj and TJ operators and extract their operands. You might also need to reverse some ligatures though.

Producing nice semantic HTML is much harder, though also easy if you don't mind every word in a separate absolutely positioned div.

Many PDF reader software already contains empirically tuned routines to infer the text flow and generate text files (because the software needs to handle Select All and Copy), but they often produce bad results.

But if you just want to read a PDF on a remote machine over ssh, the easiest solution might be just transferring the file and then opening it locally, or use X forwarding and open the PDF with a graphic reader.

Re:Chrome 59 has cross-platform headless support by jevinskie on Wednesday April 12, 2017 @07:08PM (#14102589)
You might be able to tweak this pdf.js example to dump out its canvas element after it renders.

https://github.com/mozilla/pdf.js/blob/master/examples/learn...

Re:Chrome 59 has cross-platform headless support by desdiv on Wednesday April 12, 2017 @08:44PM (#14103105)
Re:Chrome 59 has cross-platform headless support by ufmace on Wednesday April 12, 2017 @10:19PM (#14103605)
Easy, not so much, depending on exactly what you want to get out of it. I did a project with this once https://www.idrsolutions.com/jpdf2html5/. Last I checked, they only supported it as a Java library that could generate rather nice looking and complete HTML pages from PDF documents. The output was great, but it was kinda pricey and difficult to work with.

On the opposite side of the complexity level, I have also used this http://www.pdfsharp.com/PDFsharp/ to extract bits of text from PDFs. It's free, but you only get access to the raw PDF text with formatting codes. It works fine if you just want to grab a short string, but you got your work cut out for you if you want to do anything more sophisticated.

Re:Chrome 59 has cross-platform headless support by uptown on Wednesday April 12, 2017 @06:53PM (#14102499)
Not sure of your exact use-case, but mPDF does this well.

https://github.com/mpdf/mpdf

Re:Chrome 59 has cross-platform headless support by frik on Thursday April 13, 2017 @12:37AM (#14104201)
Especially it should adhere to CSS3 page break properties.
Re:Chrome 59 has cross-platform headless support by zwerdlds on Wednesday April 12, 2017 @06:19PM (#14102261)
FWIW, you can do that now, using phantomjs (which is chrome) http://phantomjs.org/screen-capture.html
Re:Chrome 59 has cross-platform headless support by dasmoth on Wednesday April 12, 2017 @06:28PM (#14102332)
It's a useful tool (and huge thanks to those who built it -- and SlimerJS for that matter) but whenever I've reached for there's always been some issue to resolve, generally relating to the exact version and/or set of APIs supported. Headless mode (with PDF support -- which it looks like the latest version of the Chromium remote protocol does indeed have) built into a mainstream browsers is nearly guaranteed to be a smoother experience.
Re:Chrome 59 has cross-platform headless support by velodrome on Wednesday April 12, 2017 @06:23PM (#14102288)
> FWIW, you can do that now, using phantomjs (which is chrome) http://phantomjs.org/screen-capture.html

It's based on webkit.

Re:Chrome 59 has cross-platform headless support by theandrewbailey on Wednesday April 12, 2017 @06:50PM (#14102478)
Once upon a time, but not anymore.

https://www.chromium.org/blink

Re:Chrome 59 has cross-platform headless support by rubber_duck on Wednesday April 12, 2017 @07:24PM (#14102673)
PhantomJS is based on webkit (and an outdated version IIRC + a shitty JS interpreter)
Re:Chrome 59 has cross-platform headless support by chickenfries on Wednesday April 12, 2017 @06:37PM (#14102379)
Re:Chrome 59 has cross-platform headless support by erichurkman on Wednesday April 12, 2017 @08:27PM (#14102997)
And, if you need much higher fidelity and control of HTML/CSS -> PDF, there's the fantastic Prince library, http://princexml.com/ (nonfree)

(I've been using Prince for over a decade, rendering everything from prescription labels, packing slips, receipts, resumes, books, and more. It's great.)

Re:Chrome 59 has cross-platform headless support by jamespaden on Thursday April 13, 2017 @11:45AM (#14107974)
That's also an API service, http://docraptor.com, with a different pricing model that uses the Prince library for PDF rendering.
Re:Chrome 59 has cross-platform headless support by pharrlax on Wednesday April 12, 2017 @06:55PM (#14102509)
Tried all of these and haven't found any as good as http://www.nightmarejs.org/
Re:Chrome 59 has cross-platform headless support by swah on Thursday April 13, 2017 @06:45AM (#14105714)
Thats just phantomJS though..
Re:Chrome 59 has cross-platform headless support by pharrlax on Thursday April 13, 2017 @08:20AM (#14106148)
It switched to Electron under the hood a while back.
Re:Chrome 59 has cross-platform headless support by chews on Wednesday April 12, 2017 @06:25PM (#14102304)
specifically it's qtwebkit and an old version of it.
Re:Chrome 59 has cross-platform headless support by eppsilon on Wednesday April 12, 2017 @10:42PM (#14103709)
They recently released a beta version based on a newer version of QtWebKit:

https://bitbucket.org/ariya/phantomjs/downloads/

Re:Chrome 59 has cross-platform headless support by zwerdlds on Thursday April 13, 2017 @04:16PM (#14110566)
Tough crowd.