Skip to main content

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 content key of your document definition is where your PDF actually lives. It holds an ordered array of content nodes — objects (or plain strings) that pdfmake lays out from top to bottom, wrapping across pages as needed. Every visible element in your document — a paragraph, a table, an image, a list — is represented as a node in this array.

The content array

At its simplest, content is a flat JavaScript array. Each entry is either a plain string (treated as a paragraph) or a node object that carries both content and rendering instructions:
const docDefinition = {
  content: [
    'First paragraph',
    'Another paragraph, this time a little bit longer to make sure, this line will be divided into at least two lines'
  ]
};
Nodes are rendered in array order, stacked vertically. When a node overflows a page, pdfmake automatically continues it on the next page.

Plain strings vs text objects

The most common node type is text. pdfmake accepts both a raw string and a full text object:
content: [
  // Plain string — shorthand for { text: '...' }
  'Hello, world!',

  // Text object with inline style overrides
  {
    text: 'Paragraphs can also be styled without using named-styles (this one sets fontSize to 25)',
    fontSize: 25
  },

  // Text object with italics
  {
    text: 'This paragraph does not use a named-style and sets fontSize to 8 and italics to true',
    fontSize: 8,
    italics: true
  }
]
A text node can also hold an array of inline runs, letting you mix styles within a single paragraph:
{
  text: [
    'Hello World.',
    { text: '1, 2', sup: true },
    " Let's continue our sentence. Notice the leading space."
  ]
}

Common node properties

These properties are available on virtually every node type, regardless of whether it is a text block, a list, a table, or a columns layout.

style

A named style string or array of style strings to apply. Styles are defined in the top-level styles map. Multiple styles are applied left to right; later styles win conflicts.

margin

Extra space outside the node. Accepts a single number (all sides), [horizontal, vertical], or [left, top, right, bottom].

alignment

Text alignment: 'left' (default), 'center', 'right', or 'justify'.

pageBreak

Force a page break relative to this node. Use 'before' to start a new page before the node, or 'after' to break after it.

id

A string identifier for the node. Used as an anchor target for internal cross-references and table-of-contents entries.

opacity

A number between 0 (invisible) and 1 (fully opaque). Applies to text and other visual nodes.
Margins are not inherited by child nodes. A margin on a stack applies to the stack as a whole; the nodes inside the stack do not automatically pick it up.

Node types overview

pdfmake’s layout engine recognises the following node types, detected by which key is present on the node object.

text — Paragraphs and inline runs

The most basic node. Renders one or more lines of text. The text value can be a string or an array of inline run objects.
{ text: 'A simple paragraph.' }

ul — Unordered list

Renders a bulleted list. Items can be strings or nested node objects.
{
  ul: [
    'item 1',
    'item 2',
    'item 3'
  ]
}

ol — Ordered list

Renders a numbered list. Supports start, reversed, and per-item counter overrides.
{
  ol: [
    'item 1',
    'item 2',
    'item 3'
  ]
}

table — Data tables

Renders a grid of cells. The table object requires a body array of row arrays, and optionally widths, heights, and headerRows.
{
  table: {
    widths: ['*', 'auto', 100],
    body: [
      ['Column 1', 'Column 2', 'Column 3'],
      ['Row 1 – Cell 1', 'Row 1 – Cell 2', 'Row 1 – Cell 3']
    ]
  }
}

image — Raster images

Embeds a JPEG or PNG image. Reference images by a key defined in the top-level images map, or supply a URL or base64 data URI directly. Use width, height, or fit to control sizing.
{ image: 'myPhoto', width: 300 }

svg — Vector graphics

Embeds an inline SVG string. Both width and height must be defined.
{ svg: '<svg ...>...</svg>', width: 100, height: 100 }

canvas — Vector shapes

Low-level drawing API for lines, rectangles, ellipses, and polylines using pdfmake’s own canvas primitives.
{
  canvas: [
    { type: 'rect', x: 0, y: 0, w: 100, h: 50, color: '#cccccc' }
  ]
}

columns — Side-by-side layout

Splits the available width into two or more columns. Each column is itself a content node (or an array of nodes). Column widths can be fixed numbers, '*' (star / equal share), or 'auto' (fit content).
{
  columns: [
    { width: '*', text: 'Left column content...' },
    { width: '*', text: 'Right column content...' }
  ]
}

stack — Vertical group

Groups multiple nodes into a single logical block. Useful for applying a shared style or margin to a set of nodes, or for nesting content inside columns.
{
  stack: [
    'First line in the stack',
    { text: 'Second line', style: 'subheader' }
  ],
  style: 'header'
}

toc — Table of contents

Generates an automatic table of contents from all nodes that carry tocItem: true. The title property is itself a content node.
{
  toc: {
    title: { text: 'INDEX', style: 'header' },
    numberStyle: { bold: true }
  }
}
Mark items to appear in the TOC with tocItem: true:
{ text: 'Chapter 1', style: 'header', tocItem: true }

qr — QR codes

Renders a QR code for the given string value. Control the size with fit.
{ qr: 'https://example.com', fit: 100 }

attachment — File attachments

Embeds a file attachment into the PDF. The attachment node does not render visible content on the page but is included in the document. Use width and height to control the invisible placeholder size (defaults: 7 × 18 pt).
{
  attachment: 'path/to/file.txt',
  description: 'Attached text file'
}

Nesting content

Content nodes can contain other content nodes. Columns hold arrays of nodes; stacks hold arrays of nodes; table cells hold nodes. This composability lets you build complex layouts from simple primitives.
{
  columns: [
    {
      width: 100,
      fontSize: 9,
      text: 'A narrow left column with smaller text.'
    },
    [
      // An array is treated as a stack of paragraphs
      'This column is defined as an array.',
      'Each entry is a separate paragraph.',
      {
        columns: [
          { text: 'Nested left' },
          { text: 'Nested right' }
        ]
      }
    ]
  ]
}
When a column entry is a plain array (not an object with a columns key), pdfmake treats it as a stack of paragraphs rendered one below another — identical to the top-level content array.

The stack type for grouping

A stack node wraps multiple child nodes and renders them vertically. Its main use case is applying a shared style or margin to a group without affecting the children individually:
{
  stack: [
    'This header has both top and bottom margins defined',
    { text: 'This is a subheader', style: 'subheader' }
  ],
  style: 'header'
}
In this example, fontSize from the header style is inherited by both children, but any margin set on the header style applies only to the outer stack node.

Page break control

Static page breaks

Add pageBreak: 'before' to start a new page immediately before a node, or pageBreak: 'after' to break after it:
{
  text: 'This paragraph starts on a new page.',
  pageBreak: 'before'
}
{
  text: 'A page break is forced after this text.',
  pageBreak: 'after'
}

Dynamic page breaks with pageBreakBefore

For more control, define a pageBreakBefore callback at the document level. pdfmake calls it before placing each node and passes the node’s info plus an object with three lazy getter functions. Return true to insert a page break before that node:
const docDefinition = {
  content: [ /* ... */ ],
  pageBreakBefore: function (currentNode, { getFollowingNodesOnPage, getNodesOnNextPage, getPreviousNodesOnPage }) {
    // Force a break before any node tagged as a top-level heading
    // when it would be the last item on the page
    return currentNode.headlineLevel === 1 && getFollowingNodesOnPage().length === 0;
  }
};
The callback parameters are:
ParameterDescription
currentNodeThe node info object about to be placed
getFollowingNodesOnPage()Lazy getter — returns nodes already committed to the current page after currentNode
getNodesOnNextPage()Lazy getter — returns nodes that will appear on the next page
getPreviousNodesOnPage()Lazy getter — returns nodes already placed on the current page before currentNode
The three node-context helpers are getter functions, not plain arrays. Call them as getFollowingNodesOnPage() rather than accessing them as properties.

Styling properties on nodes

Beyond style, you can set any supported typography or layout property directly on a node. These inline overrides take priority over named styles and defaultStyle:
content: [
  {
    text: 'Paragraphs can also be styled without using named-styles (this one sets fontSize to 25)',
    fontSize: 25
  },
  {
    text: 'Opacity example',
    opacity: 0.4
  },
  {
    text: 'Preserve leading spaces for code-like content',
    preserveLeadingSpaces: true
  },
  {
    text: [
      'Superscript: H',
      { text: '2', sup: true },
      'O'
    ]
  },
  {
    text: [
      'Subscript: CO',
      { text: '2', sub: true }
    ]
  }
]

Next steps

Overview

Return to the document definition overview to see how content fits alongside styles, page layout, and security settings.

Page Layout

Configure page size, orientation, margins, and per-section settings.

Build docs developers (and LLMs) love