pdfmake embeds fonts directly in the generated PDF so the document looks identical everywhere it is opened. To accomplish this, it uses a Virtual File System (VFS) — an in-memory map of filenames to base64-encoded font data — that lets both browser and Node.js environments load font files in the same way.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.
The Virtual File System (VFS)
The VFS is a plain JavaScript object whose keys are filenames and whose values are either base64-encoded strings or rawBuffer/Uint8Array data. pdfmake reads font files from the VFS at render time rather than from the real filesystem, which is why the same API works in the browser and on the server.
The standard distribution ships a pre-built VFS (pdfmake/build/vfs_fonts.js) that contains the Roboto typeface in four variants: regular, medium (used as bold), italic, and medium-italic.
Default Setup: Roboto in the Browser
In a browser bundling workflow, import the pre-built VFS and register it usingaddVirtualFileSystem before calling createPdf:
pdfmake/build/vfs_fonts.js is loaded directly as a <script> tag in a browser, it automatically calls pdfMake.addVirtualFileSystem(vfs) on the global pdfMake instance — no additional setup is required.
The browser build already registers Roboto as the default font family, so no additional font configuration is needed for documents that use the default font.
Default Setup: Roboto in Node.js
In Node.js thepdfmake package exports a server-side instance. The Roboto font object lives in a separate module under fonts/Roboto:
Roboto is a plain object of the shape { Roboto: { normal, bold, italics, bolditalics } } where each value is a file path on disk that pdfmake resolves via the local access policy.
Font Definition Object
Regardless of environment, fonts are registered as an object where each key is the family name used in content/styles, and each value is an object mapping the four style variants to a VFS key or file path:normal. The values are looked up as keys in the VFS (browser) or as file paths on disk (Node.js).
Font Management Methods
The pdfmake instance exposes three methods for managing registered fonts:Merges
fonts into the current font registry. Use this to add families without removing the ones already registered (such as Roboto).Replaces the entire font registry with
fonts. All previously registered families (including Roboto) are removed.Removes all registered fonts. Call before
setFonts or addFonts when you need a clean slate.Using a Custom Font in Node.js
Prepare your font files
Place your TrueType (
.ttf) or OpenType (.otf) files in a directory accessible to your Node.js process, for example ./fonts/.Node.js resolves font file paths relative to the current working directory of the process (
process.cwd()), not relative to the source file. Make sure the paths you provide are correct relative to where you run node.Browser Methods: VFS and Font Containers
The browser build of pdfmake provides two additional helper methods beyondaddFonts/setFonts/clearFonts:
addVirtualFileSystem(vfs)
Merges an object of { filename: base64Data } entries into the in-memory VFS. This is the low-level method the browser build uses to make font data available before rendering.
addFontContainer(fontContainer)
A convenience method that calls addVirtualFileSystem(fontContainer.vfs) and addFonts(fontContainer.fonts) in one step. A font container is any object with a vfs key (the VFS entries) and a fonts key (the font definition object):
Building a Custom VFS Bundle
For browser projects that need custom fonts, the recommended approach is to build a customvfs_fonts.js file using the build-vfs.js script included in the pdfmake repository:
build/vfs_fonts.js that you can import into your project in place of the default file.