The pdfmake library exposes a singleton instance that serves as the central entry point for all PDF generation. You register fonts and custom table layouts on this instance, configure security policies, then callDocumentation 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.
createPdf() to receive an OutputDocument ready for export. This page documents every method available on the singleton.
Getting the Instance
- Node.js
- Browser (bundler)
- Browser (script tag)
In Node.js environments, require the compiled entry point. The module exports a pre-constructed singleton — no
new call is needed.createPdf()
createPdf is the primary method of the pdfmake instance. It validates the document definition, configures an internal printer with the registered fonts and layouts, and returns an OutputDocument (browser) or OutputDocumentServer (Node.js) that you use to export the PDF.
The document definition object. Must contain at minimum a
content property. Supports pageSize, pageMargins, styles, defaultStyle, header, footer, background, images, and more.Optional generation options object. Any
progressCallback and tableLayouts values you set here will be overwritten by the values registered on the singleton instance via setProgressCallback() and addTableLayouts().OutputDocument in browser environments, OutputDocumentServer in Node.js. Both share a common base; see the Output Document API for the full method list.
On Node.js, if you have not called
setUrlAccessPolicy() or setLocalAccessPolicy() before invoking createPdf(), pdfmake will print a warning to the console encouraging you to restrict external resource access.Font Management
pdfmake requires fonts to be registered on the instance beforecreatePdf() is called. In the browser, Roboto is pre-registered; in Node.js you must provide your own font map. Each font family is an object whose keys are the four style variants: normal, bold, italics, and bolditalics.
addFonts()
Merges additional font definitions into the existing font registry. Existing font families are preserved unless overwritten by the new object.A font map where each key is a family name and the value is an object with optional
normal, bold, italics, and bolditalics string properties pointing to font file paths or VFS keys.setFonts()
Replaces the entire fonts registry with the supplied object. Any previously registered fonts — including the browser default Roboto — are discarded.The complete font map that replaces the current registry.
clearFonts()
Resets the fonts registry to an empty object. Call this beforesetFonts() when you want to ensure no previously loaded families linger in the registry.
Table Layout Management
Custom table layouts let you control border widths, padding, and fill colors for individual tables. You register layouts on the instance by name; document definitions then reference them by that name inlayout: 'myLayout'.
addTableLayouts()
Merges the supplied layout map into the existing custom layouts registry.An object whose keys are layout names and whose values are layout descriptor objects. Each descriptor may define
hLineWidth, vLineWidth, hLineColor, vLineColor, paddingLeft, paddingRight, paddingTop, paddingBottom, and fillColor as functions or static values.setTableLayouts()
Replaces the entire table layouts registry with the supplied object.The complete table layout map that replaces the current registry.
clearTableLayouts()
Removes all custom table layouts, resetting the registry to an empty object.Callbacks and Policies
setProgressCallback()
Registers a function that pdfmake calls periodically during document generation to report rendering progress. This is useful for displaying progress bars in long-running documents.A function called with a progress value as document pages are processed.
setUrlAccessPolicy()
Registers a callback that is invoked for every external URL pdfmake attempts to load (for example, remote images). Returntrue to allow the request or false to block it.
A function with signature
(url: string) => boolean. Pass undefined to remove a previously set policy. On Node.js, omitting this policy emits a console warning when createPdf() is called.setLocalAccessPolicy()
Registers a callback that is invoked for every local file path pdfmake attempts to read from disk. Returntrue to permit access or false to deny it.
setLocalAccessPolicy() is available only in the Node.js build (src/index.js). It is not present in the browser bundle.A function with signature
(path: string) => boolean. Pass undefined to remove a previously set policy. On Node.js, omitting this policy emits a console warning when createPdf() is called.Browser-Only Methods
The following methods are available only on the browser build of pdfmake (build/pdfmake.js). They manage the in-memory virtual file system that the browser uses in place of the Node.js fs module.
addVirtualFileSystem()
Iterates over the supplied VFS map and writes each entry into the virtual file system. Each entry can be a raw base64 string or an object withdata and optional encoding fields (defaults to 'base64').
A map from file name (string key) to either a base64-encoded string or an object
{ data: string, encoding?: string }. This is the same shape produced by the pdfmake build-vfs.js script.addFontContainer()
Convenience method that registers a font container — an object with both avfs map and a fonts map — in a single call. It is equivalent to calling addVirtualFileSystem(fontContainer.vfs) followed by addFonts(fontContainer.fonts).
An object with two required properties:
vfs— a VFS map (same shape asaddVirtualFileSystem)fonts— a font registry map (same shape asaddFonts)