explaingit

foliojs/pdfkit

10,655JavaScriptAudience · developerComplexity · 2/5LicenseSetup · easy

TLDR

PDFKit is a JavaScript library for creating PDF files programmatically in Node.js or the browser, supporting text, images, vector shapes, custom fonts, fillable forms, and encryption.

Mindmap

mindmap
  root((PDFKit))
    What it does
      Generate PDF files
      Text and images
      Vector shapes
    Features
      Custom fonts
      Fillable forms
      Encryption
    Environments
      Node.js
      Browser
      webpack build
    Audience
      Backend developers
      Frontend developers
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Generate PDF invoices or reports in a Node.js backend by writing JavaScript that describes the document layout.

USE CASE 2

Create a browser-based PDF export feature where users download a styled document without any server-side processing.

USE CASE 3

Build a PDF with custom fonts, embedded images, and clickable links for a digital product catalog.

USE CASE 4

Add fillable form fields to a PDF document for e-signatures or data collection workflows.

Tech stack

JavaScriptNode.jsBrowserifywebpack

Getting it running

Difficulty · easy Time to first run · 30min
Use freely for any purpose including commercial products, as long as you include the MIT license notice.

In plain English

PDFKit is a JavaScript library for generating PDF files from code, usable in both Node.js server environments and directly in a web browser. Instead of filling out a PDF template by hand, you write JavaScript that describes the document: add a page, set a font, write some text, draw a shape, embed an image, and then export the result as a PDF file. The API is designed to be chained, meaning you can write a sequence of calls one after another without storing intermediate results. The library handles the technical details of the PDF format for you, including font embedding, page layout, and binary encoding. In terms of features, PDFKit can render text with automatic line wrapping and alignment, embed custom fonts in TrueType and OpenType formats, include JPEG and PNG images, draw vector shapes and paths using an interface similar to the HTML canvas element, and add annotations such as links, highlights, and underlines. It also supports fillable form fields (AcroForms), document outlines for navigation, PDF encryption, and access control settings such as restricting printing or copying. For browser use, PDFKit works with build tools like Browserify or webpack, or you can load a prebuilt standalone file without any build step. Output in the browser is streamed to a Blob object, which can be displayed in an iframe or uploaded to a server. Installation for Node.js projects is through npm or yarn with a single command. The documentation and a programming guide are available on the project website, and the guide itself is distributed as a PDF generated by PDFKit, which serves as a live example of the library's output. The library is released under the MIT license.

Copy-paste prompts

Prompt 1
Using PDFKit in Node.js, write code to generate a PDF invoice with a header, an itemized table, and a total, then save it to disk.
Prompt 2
Show me how to embed a custom TrueType font in a PDFKit document and render multi-column text with automatic line wrapping.
Prompt 3
Write browser-side JavaScript that uses PDFKit to let a user download a PDF generated from form input, without a server.
Prompt 4
Using PDFKit, create a PDF with a cover page image, a table of contents with anchor links, and multiple pages of wrapped text.
Prompt 5
Show me how to add password protection and disable the print permission on a PDF generated with PDFKit.
Open on GitHub → Explain another repo

← foliojs on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.