Live data from Hacker News

Pdfmake – PDF printing in pure JavaScript

pdfmake.org

21–30 of 49 posts

Re: Pdfmake – PDF printing in pure JavaScript

#21

Right now I'm using PhantomJS to render an HTML page. It supports styling via CSS, multiple pages, etc etc. What advantages does this have?

PhantomJS is a full web browser that just happens to output PDF's. This is a library to create PDF's with it's own layout model that shares nothing with HTML. Much simpler and low level.

Is it really simpler? I have to learn a DSL to create PDFs with this, whereas I can just use HTML in the other case.

Re: Pdfmake – PDF printing in pure JavaScript

#22

Earlier quoted context omitted.

PhantomJS is a full web browser that just happens to output PDF's. This is a library to create PDF's with it's own layout model that shares nothing with HTML. Much simpler and low level.

Is it really simpler? I have to learn a DSL to create PDFs with this, whereas I can just use HTML in the other case.

You are using a school bus to transport one person.

Re: Pdfmake – PDF printing in pure JavaScript

#23

Earlier quoted context omitted.

PhantomJS is a full web browser that just happens to output PDF's. This is a library to create PDF's with it's own layout model that shares nothing with HTML. Much simpler and low level.

Is it really simpler? I have to learn a DSL to create PDFs with this, whereas I can just use HTML in the other case.

It's not like there is a direct translation from HTML to PDF. They don't really map 1:1. The PDF exported by a browser from an HTML page is an interpretation of that content. Converting from HTML is not a straightforward, reliable way to produce PDFs. Sometimes the process turns out beautiful, sometimes it turns out kind of shitty. Not to mention there are PDF features which are not supported by an HTML export (for example, forms).

A DSL designed for PDF creation is a much better way to approach this. It gives you way more control over what you're doing. Concerning pdfkit specifically, I think a JSON file is a gruesome way to design a PDF, but IMO it's still better than converting from HTML unless you're doing something very simple.

Re: Pdfmake – PDF printing in pure JavaScript

#24

Earlier quoted context omitted.

Is it really simpler? I have to learn a DSL to create PDFs with this, whereas I can just use HTML in the other case.

You are using a school bus to transport one person.

But the bus is free and it works fine.

Re: Pdfmake – PDF printing in pure JavaScript

#25
Nice. This is something I have wanted to find time to write and I'm glad somebody else already has.

I use pdfkit because I have an offline-capable JS app with fairly rich document printing needs. A friendly layout engine on top can save a lot of effort making nice designs.

Re: Pdfmake – PDF printing in pure JavaScript

#26
post #2

Just looked at the sample on the playground section of the website. No hyphenation, no ligatures, and overall the output looks ugly (compared to TeX). What is the advantage over simply creating an appropriate LaTeX/ConTeXt document in the background and serving that?

For the same reason everything eventually gets rewritten in Javascript: sometimes you want to do it in a browser.

In my case, I have a Javascript app that stores critical information for offline use, and users want to be able to print that information nicely. So I generate PDFs in Javascript. This could make that much easier.

Re: Pdfmake – PDF printing in pure JavaScript

#29

pdfmake is based on my PDFKit project http://github.com/devongovett/pdfkit , which does the actual PDF generation under the hood. pdfmake is a layout engine on top of PDFKit supporting a nice declarative json document description format.

Has anyone here done a comparison of server-side PDF generators? PDFKit, ReportLab, etc?
Post reply on HN