PDFKit

Package

JavaScript library that draws PDF documents from code in Node.js and the browser

Price
Free, open source
Access
None, runs locally

About

MIT-licensed library with a chainable API for building PDFs: wrapped text and lists, embedded fonts and images, vector graphics, tables, links and annotations, AcroForms, encryption and tagged PDF/UA output. It does not render HTML; your code places the content.

What you can do with it

  • Generate invoices or reports as PDFs from a Node.js server
  • Stream a generated PDF straight into an HTTP response
  • Build fillable PDF forms with AcroForm fields in JavaScript

Get started

  1. Install the package with npm install pdfkit
  2. Pipe the document to a file or HTTP response, then call doc.end()

Example

const { PDFDocument } = require('pdfkit');
const fs = require('fs');

// Create a document
const doc = new PDFDocument();

// Pipe its output somewhere, like to a file or HTTP response
doc.pipe(fs.createWriteStream('output.pdf'));

// Embed a font, set the font size, and render some text
doc
  .font('fonts/PalatinoBold.ttf')
  .fontSize(25)
  .text('Some text with an embedded font!', 100, 100);

// Add an image, constrain it to a given size, and center it vertically and horizontally
doc.image('path/to/image.png', {
  fit: [250, 300],
  align: 'center',
  valign: 'center'
});

// Finalize PDF file
doc.end();

Details

Hosting
Runs locally
Available in
Worldwide
Official SDKs
JavaScript/TypeScript
MCP server
None

Tasks

Alternatives

Other tools for the same tasks.

Last checked on .