Every PDF you generate with pdfmake starts from a single plain JavaScript object — the document definition (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.
docDefinition). You pass it to pdfmake.createPdf(docDefinition) and pdfmake handles the rest: layout, pagination, fonts, and rendering. Understanding the shape of this object is the foundation of everything else in pdfmake.
What is the document definition?
The document definition is a declarative description of your entire PDF. It tells pdfmake what content to render, how pages should be sized and oriented, what styles to apply, whether the file should be password-protected, and much more. There is no imperative drawing API — you describe the document as data, and pdfmake figures out the layout.createPdf accepts a plain object and returns a document object you can stream, download, or write to disk. The only field that is strictly required is content.
Top-level structure
Below is a fully-annotated skeleton that shows every major key you can place at the root of a document definition.Only
content is required. Every other key is optional and falls back to a sensible default when omitted.Key-by-key reference
content
An array of content nodes — text, images, tables, lists, and more. This is the only required field. See the Content Nodes page for the full node type reference.
pageSize / pageOrientation / pageMargins
Control the physical dimensions of every page. Supports standard paper names like
'A4' or custom { width, height } objects. See Page Layout for all options.header / footer
Functions called for every page that return a content node (or
null). Receive currentPage, pageCount, and pageSize as arguments.background
A function returning a content node rendered behind the page content on every page. Receives
currentPage and pageSize. Useful for watermark-style images or tinted backgrounds.watermark
A shortcut for diagonal text watermarks. Accepts a plain string or an object with
text, color, opacity, bold, italics, and fontSize.styles / defaultStyle
Named style definitions and the document-wide default. Styles cascade through the content tree. See the Styles system section below.
info
PDF metadata embedded in the file:
title, author, subject, keywords, creator, and producer.userPassword / ownerPassword / permissions
Encrypt the PDF and control what readers and owners are allowed to do (print, copy, annotate, etc.).
compress
Boolean (default
true). Enables zlib compression of the PDF content stream, reducing file size.pageBreakBefore
A callback invoked before each node is placed. Return
true to force a page break before that node. The second argument is an object with lazy getter functions for node context. See Page Layout for the full signature.Styles system
pdfmake’s style system lets you define reusable style objects in the top-levelstyles map, then reference them by name from any content node. Styles can cascade, inherit, and be combined.
Named styles
Define styles in thestyles map at the top level of the document definition:
Style inheritance with extends
A style definition can extend one or more named styles using the extends property. Pass a single style name or an array of style names:
defaultStyle
The defaultStyle key sets document-wide defaults for every node. Any property set here acts as the baseline before named styles or node-level overrides are applied:
Inline style overrides
Any styling property (fontSize, bold, color, alignment, etc.) can be set directly on a content node without using a named style:
defaultStyle.
Cascade order (lowest → highest priority)
defaultStyle- Named styles (in array order if multiple)
- Inline properties on the node itself
Minimal working example
The simplest possible document definition requires onlycontent:
Next steps
Content Nodes
Learn how to build the
content array with text, images, tables, lists, columns, and more.Page Layout
Configure page size, orientation, margins, headers, footers, and multi-section documents.