Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/bpampuch/pdfmake/llms.txt

Use this file to discover all available pages before exploring further.

pdfmake is an open-source JavaScript library that turns a plain JavaScript object — called a document definition — into a fully formatted PDF. It runs entirely in the browser or in a Node.js process, with no native binaries, no server round-trips, and no external tools required. Whether you’re generating invoices, reports, or certificates, the same API works everywhere.

How it works

The central concept in pdfmake is the document definition object (docDefinition). You describe what the document should contain — text, tables, images, headers, footers, page margins — as a plain JavaScript object, then pass it to createPdf(). pdfmake’s layout engine handles line wrapping, page breaking, font embedding, and rendering, and hands you back a document object you can download, open, print, or stream to disk.
const docDefinition = {
  content: [
    { text: 'Hello, pdfmake!', fontSize: 24, bold: true },
    'This paragraph is generated entirely in JavaScript.'
  ]
};

const pdf = pdfmake.createPdf(docDefinition);
// In the browser:
pdf.download('hello.pdf');
// In Node.js:
pdf.write('hello.pdf');
The pipeline is always the same: document definition → createPdf() → output document → deliver.

Browser vs Node.js

pdfmake ships two entry points that share the same declarative API but deliver the output differently.
EnvironmentImportDelivery methods
Browserpdfmake.min.js bundledownload(), open(), print(), getBlob(), getBase64(), getDataUrl()
Node.jsrequire('pdfmake')write(filename), getBuffer(), getBase64(), getStream()
In the browser the bundle exposes a pre-configured singleton with Roboto fonts already wired up. In Node.js you add fonts yourself with pdfmake.addFonts() before calling createPdf().

Key features

pdfmake supports a rich set of layout and typography primitives out of the box:
  • Automatic line-wrapping and page-breaking
  • Text alignment: left, right, center, and justified
  • Ordered (ol) and unordered (ul) lists, with nesting and custom marker types
  • Tables with auto/fixed/star-sized columns, colSpan, rowSpan, and repeated headers
  • Columns and snaking (newspaper-style) layouts
  • Images (JPEG/PNG) and SVG vector graphics
  • Convenient named styles and style inheritance
  • Static and dynamic page headers and footers with access to current page number and total
  • Background layers and watermarks
  • Document sections, custom page breaks, and page dimensions/orientations
  • Font embedding — including custom typefaces via the virtual file system
  • Table of contents
  • PDF metadata (author, subject, keywords)

Explore the features

Text Styling

Fonts, sizes, colors, alignment, inline rich text, and named style inheritance.

Tables

Column widths, row/col spans, repeated headers, custom layouts, and cell styling.

Images & SVG

Embed raster images and SVG graphics with fit, cover, and positioning options.

Custom Fonts

Embed any TrueType or OpenType font using the virtual file system.

Headers & Footers

Static or dynamic content with access to current page number and total page count.

PDF Security

Password protection, permissions, and encryption for generated documents.

The virtual file system (vfs)

pdfmake uses an in-memory virtual file system to store binary assets — primarily font files — so they are available in environments (like the browser) that have no real file system access. When you include vfs_fonts.js in the browser, it populates this virtual FS with the Roboto font family. In Node.js, fonts are referenced by their actual file system paths, so no vfs setup is needed for the built-in Roboto font. For custom fonts in the browser you use pdfmake.addVirtualFileSystem() or pdfmake.addFontContainer() to register the base64-encoded font data.

Next step

Ready to generate your first PDF? Follow the Quickstart to have a working document in under five minutes.

Build docs developers (and LLMs) love