
Pdfmake – PDF printing in pure JavaScript - tilt
http://pdfmake.org/#/
======
devongovett
pdfmake is based on my PDFKit project
[http://github.com/devongovett/pdfkit](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.

~~~
SiVal
Has anyone here done a comparison of server-side PDF generators? PDFKit,
ReportLab, etc?

------
adiM
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?

~~~
logicallee
>overall the output looks ugly (compared to TeX)

what doesn't!

>What is the advantage over simply creating an appropriate LaTeX/ConTeXt
document in the background and serving that?

the obvious advantage is that you wouldn't have to learn LaTeX/ConTeXt, no?

~~~
Vulume
Pdfmake could generate LaTeX, which can then be properly compiled to a pdf
(potentially with texlive.js).

In Haskell this is possible with similar DSLs. Very useful to generate
reports.

------
imaginenore
How does it compare to

Mozilla's PDF.js
[https://mozilla.github.io/pdf.js/](https://mozilla.github.io/pdf.js/)

or

Parallax's jsPDF
[https://parall.ax/products/jspdf](https://parall.ax/products/jspdf)

~~~
hliyan
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'
    	]
       }

~~~
z3t4
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!

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

------
phs2501
There's also
[https://github.com/devongovett/pdfkit](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).

~~~
abusque
pdfmake is actually built on top of pdfkit.

------
brady8
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)?

~~~
SigmundA
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...](http://docs.telerik.com/kendo-
ui/framework/drawing/drawing-dom)

------
beatpanda
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?

~~~
SigmundA
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.

~~~
beatpanda
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.

~~~
rmsaksida
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.

~~~
SigmundA
I sort of disagree, HTML as implemented in PhantomJs, wkhtmltopdf and all
interactive browsers is incomplete for paged/print output. However HTML with
CCS page media is pretty close to being a complete solution, unfortunately the
only implementation currently is the commercial PrinceXML.

If someone (Apple or Google) would get wise and implement the full paged media
spec then PhantomJS/wkhtmltopdf/your browser might be a viable option for full
fidelity print output.

See:
[http://www.webkit.org/projects/printing/](http://www.webkit.org/projects/printing/)

[http://www.princexml.com/](http://www.princexml.com/)

Until then our apps will have to suffer with one layout language for viewing
(HTML) and have another for print like this lib.

------
ef4
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.

------
seanemmer
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?

------
mp3geek
Little of topic. What would be nice is to have something like "print to pdf,
aka save page as pdf" via a browser using pdfjs.

~~~
c22
"PDF" is a valid application-agnostic printer target on the Debian box I am
using.

~~~
copperx
In OS X too. I believe Windows is the only OS that needs you to install a PDF
printer.

~~~
walterbell
On Windows, CutePDF uses Ghostscript for the virtual printer.

On iOS, Apple disabled the API for local virtual printers. There are various
"html-to-pdf" apps, but these often perform a non-interactive fetch of the
source web page, which use different auth/cookies and can result in a PDF
which is different from the one displayed by Safari.

------
zenocon
Does this support svg images (e.g. d3.js charts)?

~~~
jamespaden
Commercial, but DocRaptor does with some additional Javascript parsing on top
of PrinceMXL

------
beagle3
Does any of these PDF making solutions properly support RTL languages like
Arabic and Hebrew?

------
mhuffman
Cudos! PDF has a god-awful spec., with which I am intimate. I am impressed
with what you have been able to do. I don't think most people realize that the
spec. for PDF is over 1,000 pages is and was written by bipolar sadists.

~~~
pcthrowaway
Is this really longer than the combined specs for HTML and CSS?

