pdfmake’s declarative API means you can go from zero to a styled, multi-section PDF in just a few steps. This guide walks through installation, font configuration, building a document definition, and delivering the finished file — in both browser and Node.js.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.
Install pdfmake
Add pdfmake to your project with your preferred package manager.For browser-only usage without a bundler, see the Installation guide for CDN and prebuilt bundle options.
Import pdfmake and configure fonts
pdfmake requires at least one font to be registered before it can render text. The package ships with the Roboto family.Browser (with a bundler like webpack or Vite)In the browser, import the pre-built singleton and attach the bundled virtual file system, which contains Roboto as base64-encoded data:Node.js (CommonJS)In Node.js, require the package and point
addFonts() at the actual font files. The fonts/Roboto helper module exports the correct path map for you:The virtual file system (vfs) is pdfmake’s in-memory store for binary assets. In the browser there is no real file system, so font files must be pre-loaded into the vfs as base64 strings. The
vfs_fonts.js bundle does this automatically for Roboto. For custom fonts, see the Custom Fonts guide.Create a document definition
Everything about your PDF is described in a single plain JavaScript object. The Every node in
content array holds the document’s body — strings, styled text objects, tables, lists, images, and more.Here is a meaningful example combining styled text, an ordered list, and a simple table:content is either a plain string (rendered with the default style) or an object with explicit properties. Style inheritance flows from defaultStyle through named styles to inline properties, so you only override what you need.Generate the PDF
Pass the document definition to You can also open the PDF in a new tab or get the raw data:Node.js — write to diskYou can also get the binary buffer directly — useful for HTTP responses or further processing:
createPdf(), which returns an output document object. Call the delivery method that matches your environment.Browser — trigger a file downloadComplete working example
Below is a self-contained Node.js script you can run immediately after installing pdfmake. It combines every step above into a single file.If you see a warning such as “No URL access policy defined” or “No local access policy defined” when running in Node.js, add
setUrlAccessPolicy() and setLocalAccessPolicy() calls as shown above. These guards prevent pdfmake from inadvertently fetching remote resources or reading arbitrary local files — they are required in production Node.js usage.