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 distributed as an npm package and works in both Node.js and the browser. Node.js projects install it like any other dependency; browser projects can use a bundler such as webpack or Vite, or load the prebuilt script tags directly. This page covers every installation path and explains how to wire up the font system afterwards.
Before writing any code, try the interactive playground at https://pdfmake.org/playground.html. It lets you experiment with document definitions in real time and preview the PDF output instantly — no installation required.
Install via package manager
pdfmake requires Node.js 20 or later. Its only runtime dependencies are pdfkit, linebreak, and xmldoc — all installed automatically.
Node.js setup
After installing the package, require it and register at least one font before calling createPdf().
const pdfmake = require('pdfmake');
// The package ships a ready-made font map for Roboto
const Roboto = require('pdfmake/fonts/Roboto');
pdfmake.addFonts(Roboto);
The Roboto module resolves to a font descriptor object that points at the four .ttf files shipped with the package (Roboto-Regular.ttf, Roboto-Medium.ttf, Roboto-Italic.ttf, Roboto-MediumItalic.ttf).
Access policies (recommended for production)
When running in Node.js, pdfmake can fetch remote URLs and read the local file system on your behalf (for images referenced in document definitions). Declare explicit policies to control what is allowed:
// Allow only HTTPS image URLs
pdfmake.setUrlAccessPolicy((url) => url.startsWith('https://'));
// Allow all local file paths (restrict to a specific directory in production)
pdfmake.setLocalAccessPolicy((_path) => true);
Omitting these calls will cause pdfmake to log a warning on every createPdf() invocation.
ES module import
import pdfmake from 'pdfmake';
import Roboto from 'pdfmake/fonts/Roboto';
pdfmake.addFonts(Roboto);
Browser setup
Download the build artefacts or reference them from a CDN. You need two files:
pdfmake.min.js — the core library
vfs_fonts.js — the virtual file system pre-loaded with the Roboto font family
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.3.11/pdfmake.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.3.11/vfs_fonts.js"></script>
After both scripts load, window.pdfMake is available. The vfs_fonts.js script automatically registers Roboto, so no further font setup is needed:
// pdfMake is available globally after the script tags above
const docDefinition = { content: ['Hello from pdfmake!'] };
pdfMake.createPdf(docDefinition).download('hello.pdf');
Always load vfs_fonts.js after pdfmake.min.js. The fonts file calls into the pdfmake global and will throw if pdfmake has not been initialised first.
Option B — bundler (webpack / Vite)
Import the browser-targeted build and attach the vfs manually:
import pdfmake from 'pdfmake/build/pdfmake';
import vfsFonts from 'pdfmake/build/vfs_fonts';
pdfmake.addVirtualFileSystem(vfsFonts);
const docDefinition = { content: ['Hello from pdfmake!'] };
pdfmake.createPdf(docDefinition).download('hello.pdf');
Configuring the default Roboto font
pdfmake’s browser singleton pre-registers Roboto with the following descriptor, matching the four .ttf files in the package:
{
Roboto: {
normal: 'Roboto-Regular.ttf',
bold: 'Roboto-Medium.ttf',
italics: 'Roboto-Italic.ttf',
bolditalics: 'Roboto-MediumItalic.ttf'
}
}
You can add extra font families on top of Roboto without replacing it:
pdfmake.addFonts({
Roboto: {
normal: 'Roboto-Regular.ttf',
bold: 'Roboto-Medium.ttf',
italics: 'Roboto-Italic.ttf',
bolditalics: 'Roboto-MediumItalic.ttf'
}
});
To switch the active font across the whole document, set defaultStyle.font in your document definition:
const docDefinition = {
content: ['Hello in a custom font.'],
defaultStyle: { font: 'MyCustomFont' }
};
Custom fonts
To use a font other than Roboto you must:
- Provide the
.ttf or .otf font files.
- Register them in the virtual file system (browser) or by path (Node.js).
- Declare the font descriptor with
addFonts().
Node.js example
pdfmake.addFonts({
OpenSans: {
normal: 'path/to/OpenSans-Regular.ttf',
bold: 'path/to/OpenSans-Bold.ttf',
italics: 'path/to/OpenSans-Italic.ttf',
bolditalics: 'path/to/OpenSans-BoldItalic.ttf'
}
});
Browser example (font file loaded as base64)
// vfs must contain the base64-encoded font data keyed by filename
pdfmake.addVirtualFileSystem({
'OpenSans-Regular.ttf': '<base64-encoded-font-data>'
});
pdfmake.addFonts({
OpenSans: {
normal: 'OpenSans-Regular.ttf'
}
});
For a full walkthrough — including how to generate the base64 vfs data — see the Custom Fonts guide.
TypeScript
pdfmake does not ship its own type declarations. Install the community types from DefinitelyTyped to get full IDE autocompletion:
npm install --save-dev @types/pdfmake
Once installed, import types from @types/pdfmake:
import pdfmake from 'pdfmake/build/pdfmake';
import vfsFonts from 'pdfmake/build/vfs_fonts';
import type { TDocumentDefinitions } from 'pdfmake/interfaces';
pdfmake.addVirtualFileSystem(vfsFonts);
const docDefinition: TDocumentDefinitions = {
content: ['Hello, TypeScript!']
};
pdfmake.createPdf(docDefinition).download('typed.pdf');
What’s next
With pdfmake installed and fonts configured you are ready to start building documents. Continue with the Quickstart for a step-by-step walkthrough, or jump straight into a specific topic:
- Text Styling — fonts, sizes, alignment, inline rich text
- Tables — column widths, spans, headers, custom layouts
- Custom Fonts — embedding any TrueType/OpenType typeface