Live data from Hacker News

Wkhtmltopdf, shell utility to convert html to pdf using webkit rendering engine

code.google.com

31–40 of 40 posts

Re: Wkhtmltopdf, shell utility to convert html to pdf using webkit rendering engine

#31
WebKit is quite powerful and can be quite easily used for generating a PDF, SVG, PostScript of PNG in almost no effort.

I wrote a simple Deck.JS [1] and S5 [2] PDF converter using a few lines of scripting. These programs take a slide presentation written in HTML5 and convert them into a portable PDF document. This is very handy since you can then share a single file that includes all graphical elements (fonts, images, layout) intact.

I have a GitHub toy repo [3] where I made a few tests with WebKit. On the the programs there (screenshot.pl) even lets you use XPath to find the subnode to grab.

[1] https://github.com/potyl/perl-App-deckjs2pdf

[2] https://github.com/potyl/perl-App-s5pdf

[3] https://github.com/potyl/Webkit

Re: Wkhtmltopdf, shell utility to convert html to pdf using webkit rendering engine

#32
Tip: wkhtmltoimage is part of the package, allows you to render HTML+CSS into PNG.

I used this for a project which needed a CSS powered image builder, which created sharable images:

Builder: http://circlek-flugtag.heroku.com/entries/shipomatic Thumbnails: http://circlek-flugtag.heroku.com/entries

Re: Wkhtmltopdf, shell utility to convert html to pdf using webkit rendering engine

#33

Earlier quoted context omitted.

I used wkhtmltopdf in a previous project and found it to be extremely reliable and easy to use. I was extracting the HTML mime parts from incoming email, converting them to PDFs with wkhtmltopdf, then converting that to a PNG with ImageMagick and displaying the PNG to the user in a web browser.

Why bother with the intermediate stage and not go direct html-to-png?

Oops just noticed this comment. See my other comment (wkhtmltoimage is part of the package, allows you to render HTML+CSS into PNG, compile into x64 and place binary in your git repo directory to use on heroku)

Re: Wkhtmltopdf, shell utility to convert html to pdf using webkit rendering engine

#34

It's practically unusable when not in an environment with X11. I had to use it on a Windows system and any text would have incorrect letter-space. Every letter would bleed into the next, it's a typographic nightmare. You could use Arial Unicode MS to get a somewhat acceptable result but that won't support bold or italic text cleanly. I'm not quite sure but I think the fix isn't even part in the 0.11 release. One has…

you can use xvfb as a lightweight alternative to full X, works well.

Re: Wkhtmltopdf, shell utility to convert html to pdf using webkit rendering engine

#35
post #20
post #17

Earlier quoted context omitted.

Well, I am looking for some feedback on a project that converts XML to PDF. Give it a try: https://github.com/kelvin0/PyXML2PDF

I am looking for a command-line utility that could do: webpage2pdf 'http://bit-player.org/deck.js/limits-to-growth-Harvard-2012-03-30/ltg-talk.html#Lotka-Volterra' slide.pdf and actually work (create a sensible PDF representation of what I can see in a browser). So my feedback wouldn't be useful, as my use case is out of scope for your project: "PyXML2PDF is NOT compatible with any XHTML/HTML/CSS. It uses a small set…

It seems that what you want is deckjs2pdf, get it from CPAN [1] or GitHub [2]

[1] http://search.cpan.org/perldoc?deckjs2pdf

[2] https://github.com/potyl/perl-App-deckjs2pdf

Re: Wkhtmltopdf, shell utility to convert html to pdf using webkit rendering engine

#37
post #7

Every time I see a utility like this, I think maybe I could switch to producing some materials in HTML as the primary, or main intermediary, source format. Then I try the utility and realize that that would be silly. For example, I currently make PDF slides for talks. In theory I'd like to make HTML slides, but would still like the ability to render a PDF for a robust record. However, neither this utility (or Phantom…

I take some of it back. Getting the latest version of wkhtmltopdf and telling it to wait (probably longer than necessary) to process javascript, works pretty well.

    wkhtmltopdf --javascript-delay 10000 --no-stop-slow-scripts 'http://bit-player.org/deck.js/limits-to-growth-Harvard-2012-03-30/ltg-talk.html#Lotka-Volterra' slide.pdf
It's a bit slow, and a bit too hacky for me. But this tool does the best job of those I've seen.

And I've just received an email pointing me to: http://search.cpan.org/perldoc?deckjs2pdf https://github.com/potyl/perl-App-deckjs2pdf that will specifically deal with Deck.JS slides.

Re: Wkhtmltopdf, shell utility to convert html to pdf using webkit rendering engine

#38
post #11

I spent a lot of time 2-3 years ago assessing different tools to convert HTML+CSS to PDF [1]. At the time, this was to convert HTML plus custom tags into well-formatted legal documents. At the time the hands down winner was Prince XML [2]. It's relatively expensive ($3800 for a single server license) but it just works , works from many languages and produces beautiful results quickly (look at their samples). It doesn…

+1 for Prince XML.

Ryan Tomayko (a githubber) is extremely impressed. And when Ryan (or any other community respected hacker) is impressed, I can use that product without any further thinking.

http://tomayko.com/writings/princexml

If you are on .NET, I also recommend Essential Objects PDF library (http://www.essentialobjects.com/Products/EOPdf/Default.aspx). I have been using it for a production project and it is rock solid. At 549$/developer, it is much more affordable.

Re: Wkhtmltopdf, shell utility to convert html to pdf using webkit rendering engine

#39
Over the years I've tried various HTML to PDF utilities and have yet to find one that works correctly.

Previously I was using htmldoc, a project that was abandoned years ago and doesn't work with CSS. It worked for what I was doing but without CSS it's very inflexible and hard to maintain.

I recently moved to wkhtmltopdf but it has plenty of its own issues. The biggest problem I've found is that it doesn't wrap text between pages correctly. If you have a multi-page document it's likely the last line of text on a page will be split over 2 pages. IMO this is a show stopping bug. It has been known for a while but it seems no one is working on it.

The OS X version is broken. It was creating 5MB+ PDFs that should be about 50k. The Linux version doesn't have this bug.

Re: Wkhtmltopdf, shell utility to convert html to pdf using webkit rendering engine

#40
post #16

I use to use this, but it has started segfaulting on a large range of websites. I've since switched to cutycaps which handles all my needed features out of the box.

I think you mean http://cutycapt.sourceforge.net/ which I only found by switching back to Google; DDG was not able to decipher your type-o. :-)
Post reply on HN