README.md

PDFKit

A JavaScript PDF generation library for Node and the browser.

Description

PDFKit is a PDF document generation library for Node and the browser that makes creating complex, multi-page, printable documents easy.
It's written in CoffeeScript, but you can choose to use the API in plain 'ol JavaScript if you like. The API embraces
chainability, and includes both low level functions as well as abstractions for higher level functionality. The PDFKit API
is designed to be simple, so generating complex documents is often as simple as a few function calls.

Check out some of the documentation and examples to see for yourself!
You can also read the guide as a self-generated PDF with example output displayed inline.
If you'd like to see how it was generated, check out the README in the docs
folder.

Browser Usage

There are two ways to use PDFKit in the browser. The first is to use Browserify,
which is a Node module packager for the browser with the familiar require syntax. The second is to use
a prebuilt version of PDFKit, which you can download from Github.

In addition to PDFKit, you'll need somewhere to stream the output to. HTML5 has a
Blob object which can be used to store binary data, and
get URLs to this data in order to display PDF output inside an iframe, or upload to a server, etc. In order to
get a Blob from the output of PDFKit, you can use the blob-stream
module.

The following example uses Browserify to load PDFKit and blob-stream, but if you're not using Browserify,
you can load them in whatever way you'd like (e.g. script tags).

# require dependenciesPDFDocument =require'pdfkit'blobStream =require'blob-stream'# create a document the same way as abovedoc =newPDFDocument# pipe the document to a blobstream = doc.pipe(blobStream())
# add your content to the document here, as usual# get a blob when you're done
doc.end()
stream.on 'finish', -># get a blob you can do whatever you like withblob = stream.toBlob('application/pdf')
# or get a blob URL for display in the browserurl = stream.toBlobURL('application/pdf')
iframe.src = url

Note that in order to Browserify a project using PDFKit, you need to install the brfs module with npm,
which is used to load built-in font data into the package. It is listed as a devDependency in
PDFKit's package.json, so it isn't installed by default for Node users.
If you forget to install it, Browserify will print an error message.

Documentation

For complete API documentation and more examples, see the PDFKit website.