Note

This is a personal wip fork of the pdfkit project. Dont expect a working library (yet).

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

You can also try out an interactive in-browser demo of PDFKit here.

Installation

Installation uses the npm package manager. Just type the following command after installing npm.

npm install @moritzloewenstein/pdfkit

This fork is ESM-only. Use import; CommonJS require() is not supported.

Features

Coming soon!

Example

import { readFile, writeFile } from 'node:fs/promises';
import PDFDocument, { toBytes } from '@moritzloewenstein/pdfkit';

const fontData = await readFile('fonts/Roboto-Regular.ttf');
const doc = new PDFDocument({ font: 'Roboto', fontData });
doc.fontSize(25).text('Some text with an embedded font!');
doc.image(await readFile('images/example.png'), { fit: [250, 300] });
doc.addPage().circle(150, 150, 40).fill('#FF3300');
doc.end();
await writeFile('output.pdf', await toBytes(doc));

For more, see the examples and the Getting Started guide.

Browser Usage

Import the package with your browser bundler, fetch font bytes with fetch, and use toBlob(doc) after doc.end(). No Node.js polyfills or blob-stream are needed. Run npm run dev in this repository and open /playground/ to try the editable playground.

Documentation

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

License

PDFKit is available under the MIT license.