Live data from Hacker News

Pdfmake – PDF printing in pure JavaScript

pdfmake.org

11–20 of 49 posts

Re: Pdfmake – PDF printing in pure JavaScript

#11
I used PDFMake on a recent project and was very pleased.

One issue we ran into in browser was the huge size overhead from vfs_fonts - is there a preferred workaround to this issue (we had to serve it separately from the rest of the app), or any solution in the pipeline?

Re: Pdfmake – PDF printing in pure JavaScript

#12
post #7
post #6

Earlier quoted context omitted.

PDF.js is a Portable Document Format (PDF) viewer . jsPDF prints using: var doc = new jsPDF(); doc.setFontSize(40); doc.text(35, 25, "Paranyan loves jsPDF"); doc.addImage(imgData, 'JPEG', 15, 40, 180, 160); Pdfmake on the other hand: var dd = { content: [ 'First paragraph', 'Another paragraph, this time a little bit longer to make sure, this line will be divided into at least two lines' ] }

jsPDF doesn't trim each line like Pdfmake does. Pdfmake however supports new pages, witch jsPDF doesn't. Would be cool if Pdfmake didn't trim the lines!

jsPDF has a method called `addPage()` which adds a new page

Re: Pdfmake – PDF printing in pure JavaScript

#13

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.

Re: Pdfmake – PDF printing in pure JavaScript

#14

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?

Side note: Under the hood, PhantomJS uses wkhtmltopdf. You can probably save yourself some overhead using the wkhtmltopdf binary directly.

Re: Pdfmake – PDF printing in pure JavaScript

#15
post #8

There's also https://github.com/devongovett/pdfkit , which I've used to bulk-print ticket envelopes for an event. It does support multiple pages, as I had one PDF file per event occurrence (with 50-80 envelopes per).

pdfmake is actually built on top of pdfkit.

Re: Pdfmake – PDF printing in pure JavaScript

#16
post #3

This looks really well done. Any chance that it could emulate the functionality of wkhtmltopdf in the browser (a.k.a. CSS styling, structure from HTML)?

I would say pretty low wkhtmltopdf like PhantomJS uses Webkit to layout HTML then converts that layout to PDF, HTML layout including CSS and javascript execution is a heavy lift, this library only scratches the surface of what would be needed to cover wkhtmltopdf.

First you would need a pure js web browser, the closest thing currently being zombie I think. If you didn't care about running on the server then you could take advantage of the browser the lib is running in to get the current computed layout from the active dom and transform into the PDF layout, still a big job but the heavy lift is done by the browser. Telerik does this in their Kendo lib, where they render a active dom element to thier abstracted vector graphics model, then have PDF, SVG and Canvas renders for that: http://docs.telerik.com/kendo-ui/framework/drawing/drawing-d...

Re: Pdfmake – PDF printing in pure JavaScript

#17
post #14

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?

Side note: Under the hood, PhantomJS uses wkhtmltopdf. You can probably save yourself some overhead using the wkhtmltopdf binary directly.

No I believe both use QTWebkit directly.
Post reply on HN