ConfigsJul 7, 2026·3 min read

PDFKit — JavaScript PDF Generation for Node and Browser

A JavaScript library for generating complex, multi-page PDF documents in Node.js and the browser.

Agent ready

Ready-to-run agent install

This asset can be installed after the agent chooses its runtime, checks the plan, and runs the matching command.

Native · 98/100Policy: allow
Agent surface
Any MCP/CLI agent
Kind
Skill
Install
Single
Trust
Trust: Established
Entrypoint
PDFKit Overview
Direct install command
npx -y tokrepo@latest install 3cdfdc3d-799e-11f1-9bc6-00163e2b0d79 --target codex

Run after dry-run confirms the install plan.

Introduction

PDFKit is a JavaScript PDF generation library for Node.js and the browser. It provides a rich API for creating complex, multi-page documents with text, vector graphics, images, and embedded fonts. Unlike template-based PDF tools, PDFKit gives you full programmatic control over every element on the page, making it well suited for invoices, reports, certificates, and dynamic document workflows.

What PDFKit Does

  • Creates multi-page PDF documents from JavaScript code
  • Renders text with custom fonts, sizes, colors, and alignment
  • Draws vector graphics including lines, curves, rectangles, and paths
  • Embeds PNG, JPEG, and other image formats at specified positions
  • Supports font subsetting and Unicode text rendering

Architecture Overview

PDFKit generates PDF files by writing PDF objects directly to an output stream. It maintains an internal document tree of pages, fonts, images, and content streams. Text layout is handled by a built-in line-breaking algorithm that supports word wrap, alignment, and list formatting. The library uses a streaming architecture, so documents can be piped to files, HTTP responses, or blob URLs without buffering the entire PDF in memory.

Self-Hosting & Configuration

  • Install via npm: npm install pdfkit
  • For browser usage, bundle with webpack or another bundler and use Blob URLs
  • Register custom fonts: doc.registerFont('CustomFont', './path/to/font.ttf')
  • Set page size and margins: new PDFDocument({ size: 'A4', margin: 50 })
  • Enable automatic page breaks with the text layout engine or add pages manually

Key Features

  • Streaming PDF generation with low memory footprint
  • Built-in text layout with word wrap, columns, and lists
  • Vector graphics API mirroring HTML5 Canvas drawing commands
  • TrueType and OpenType font embedding with automatic subsetting
  • AcroForm support for interactive PDF form fields

Comparison with Similar Tools

  • jsPDF — lighter API for simpler PDFs; PDFKit has richer text layout and vector graphics
  • pdf-lib — focused on modifying existing PDFs; PDFKit is designed for creating new documents
  • Puppeteer — renders HTML to PDF via a headless browser; PDFKit generates PDFs programmatically without a browser
  • ReportLab (Python) — the Python equivalent; PDFKit brings similar capabilities to the JavaScript ecosystem

FAQ

Q: Can PDFKit run in the browser? A: Yes. Bundle it with a tool like webpack and use blobStream() to generate a downloadable PDF in the browser.

Q: How do I add images to a PDF? A: Use doc.image('path/to/image.png', x, y, { width: 200 }) to embed PNG or JPEG images.

Q: Does PDFKit support tables? A: There is no built-in table API. Use the text positioning and vector graphics API to draw table structures, or use community plugins like pdfkit-table.

Q: Can I use Google Fonts or web fonts? A: Download the TTF/OTF file and register it with doc.registerFont(). Direct web font URLs are not supported.

Sources

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets