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.

pdfmake gives you full control over the physical shape of your document. You can choose from dozens of standard paper sizes, rotate the page, fine-tune margins, and even switch page settings mid-document using sections. All of these are top-level keys in your document definition object.

pageSize — Choosing a paper size

Set pageSize to a string matching one of pdfmake’s built-in size names, or supply a custom { width, height } object. Dimensions in the built-in table are given in PDF points (1 pt ≈ 0.353 mm).

Standard page sizes

pdfmake ships with the following named sizes, sourced directly from standardPageSizes.js:
NameWidth (pt)Height (pt)Common use
4A04767.876740.79Large-format printing
2A03370.394767.87Large-format printing
A02383.943370.39Posters
A11683.782383.94Posters
A21190.551683.78Technical drawings
A3841.891190.55Spreadsheets
A4595.28841.89Standard document (default)
A5419.53595.28Booklets
A6297.64419.53Postcards
A7209.76297.64Notes
A8147.40209.76Business cards
A9104.88147.40Labels
A1073.70104.88Labels
B02834.654008.19ISO B series
B12004.092834.65ISO B series
B21417.322004.09ISO B series
B31000.631417.32ISO B series
B4708.661000.63ISO B series
B5498.90708.66Books
B6354.33498.90ISO B series
B7249.45354.33ISO B series
B8175.75249.45ISO B series
B9124.72175.75ISO B series
B1087.87124.72ISO B series
C02599.373676.54ISO C (envelope) series
C11836.852599.37ISO C series
C21298.271836.85ISO C series
C3918.431298.27ISO C series
C4649.13918.43Envelopes for A4
C5459.21649.13Envelopes for A5
C6323.15459.21Envelopes for A6
C7229.61323.15ISO C series
C8161.57229.61ISO C series
C9113.39161.57ISO C series
C1079.37113.39ISO C series
RA02437.803458.27Raw (untrimmed) A series
RA11729.132437.80Raw A series
RA21218.901729.13Raw A series
RA3864.571218.90Raw A series
RA4609.45864.57Raw A series
SRA02551.183628.35Supplementary raw A
SRA11814.172551.18Supplementary raw A
SRA21275.591814.17Supplementary raw A
SRA3907.091275.59Supplementary raw A
SRA4637.80907.09Supplementary raw A
EXECUTIVE521.86756.00US Executive
FOLIO612.00936.00US Folio
LEGAL612.001008.00US Legal
LETTER612.00792.00US Letter
TABLOID792.001224.00US Tabloid / Ledger
const docDefinition = {
  pageSize: 'A4',   // portrait A4 — the default
  content: [ /* ... */ ]
};

Custom page size

Pass an object with explicit width and height values (in PDF points) to define a non-standard page size:
const docDefinition = {
  pageSize: { width: 595.28, height: 420 },  // custom half-A4 landscape
  content: [ /* ... */ ]
};
PDF points are the native unit pdfmake uses internally. To convert from millimetres: pt = mm * 2.8346.

pageOrientation — Portrait or landscape

Set pageOrientation to 'portrait' (default) or 'landscape'. When set to 'landscape', pdfmake swaps the width and height of the chosen page size:
const docDefinition = {
  pageSize: 'A4',
  pageOrientation: 'landscape',
  content: [ /* ... */ ]
};

pageMargins — Controlling white space

pageMargins defines the inset from each edge of the page to the content area. It accepts three forms:
1

Single number — uniform margins

pageMargins: 40   // 40 pt on all four sides
2

Two-element array — horizontal and vertical

pageMargins: [40, 60]   // [left/right, top/bottom]
3

Four-element array — individual sides

pageMargins: [40, 60, 40, 60]  // [left, top, right, bottom]
const docDefinition = {
  pageSize: 'A4',
  pageMargins: [40, 60, 40, 60],
  content: [ /* ... */ ]
};
If pageMargins is omitted, pdfmake uses a built-in default margin.

Document sections

For advanced documents that mix page sizes, orientations, or per-section headers and footers, pdfmake supports sections. A section is a content node with a section array in place of the usual node-type key. Each section node can override pageSize, pageOrientation, pageMargins, header, footer, background, and watermark. The following example is drawn directly from examples/sections.js:
const docDefinition = {
  header: function () { return 'default header'; },
  footer: function () { return 'default footer'; },
  background: function () { return { text: 'global background', alignment: 'right' }; },
  watermark: 'default watermark',
  content: [
    // Section 1 — inherits all document-level layout settings
    {
      section: [
        'SECTION 1',
        'Text in section.'
      ]
    },

    // Section 2 — landscape, with its own header/footer/background/watermark
    {
      header: function (currentPage, pageCount) {
        return 'header: ' + currentPage.toString() + ' of ' + pageCount;
      },
      footer: function (currentPage, pageCount) {
        return 'footer: ' + currentPage.toString() + ' of ' + pageCount;
      },
      background: function () { return { text: 'SECTION 2 background', alignment: 'right' }; },
      watermark: 'SECTION 2 watermark',
      pageOrientation: 'landscape',
      section: [
        'SECTION 2',
        'Text in section as landscape page.'
      ]
    },

    // Section 3 — A7 portrait, no header/footer/watermark/background
    {
      header: null,
      footer: null,
      background: null,
      watermark: null,
      pageSize: 'A7',
      pageOrientation: 'portrait',
      section: [
        'SECTION 3',
        'Text in section as A7 page.'
      ]
    },

    // Section 4 — A6 portrait with tight margins
    {
      watermark: 'inherit',
      pageSize: 'A6',
      pageOrientation: 'portrait',
      pageMargins: 5,
      section: [
        'SECTION 4',
        'Text in section as A6 page with margin.'
      ]
    },

    // Section 5 — A6 landscape
    {
      watermark: 'watermark for inherit',
      pageSize: 'A6',
      pageOrientation: 'landscape',
      pageMargins: 10,
      section: [
        'SECTION 5',
        'Text in section as A6 landscape page with margin.'
      ]
    },

    // Section 6 — explicitly inherit all settings from the previous section
    {
      watermark: 'inherit',
      pageSize: 'inherit',
      pageOrientation: 'inherit',
      pageMargins: 'inherit',
      section: [
        'SECTION 6',
        'Text in section with page definition as previous page. Page size, orientation and margins are inherited.'
      ]
    },

    // Section 7 — uses its own header/footer; page size falls back to document default
    {
      header: function (currentPage, pageCount) {
        return 'header in section 8: ' + currentPage.toString() + ' of ' + pageCount;
      },
      footer: function (currentPage, pageCount) {
        return 'footer in section 8: ' + currentPage.toString() + ' of ' + pageCount;
      },
      section: [
        'SECTION 7',
        'Text in section with page definition as defined in document.'
      ]
    }
  ]
};
Setting a section property to the string 'inherit' explicitly copies that setting from the previous section. Setting it to null removes the inherited value (e.g., suppresses the document watermark for that section).

Section override precedence

Each section can specify its own values for:
PropertyDescription
pageSizePaper size for this section’s pages
pageOrientation'portrait', 'landscape', or 'inherit'
pageMarginsMargins for this section’s pages
headerHeader function, null to suppress, or omit to use the document default
footerFooter function, null to suppress, or omit to use the document default
backgroundBackground function, null to suppress
watermarkWatermark text/object, null to suppress, 'inherit' to copy previous

pageBreakBefore callback

The pageBreakBefore function at the document level lets you insert dynamic page breaks based on context. pdfmake calls it before placing each node and passes the node’s info along with an object containing three lazy getter functions. Return true to force a page break before that node:
const docDefinition = {
  content: [ /* ... */ ],
  pageBreakBefore: function (currentNode, { getFollowingNodesOnPage, getNodesOnNextPage, getPreviousNodesOnPage }) {
    // Avoid orphaned headings: break before a heading if it's the last node on a page
    return currentNode.headlineLevel === 1 && getFollowingNodesOnPage().length === 0;
  }
};
The callback receives:
ArgumentDescription
currentNodeThe node info object pdfmake is about to place
getFollowingNodesOnPage()Lazy getter — returns nodes already assigned to the current page after currentNode
getNodesOnNextPage()Lazy getter — returns nodes that will flow onto the next page
getPreviousNodesOnPage()Lazy getter — returns nodes already placed on the current page before currentNode
The three context helpers are getter functions, not plain arrays. Always call them — getFollowingNodesOnPage() — rather than accessing them as properties.
The pageBreakBefore callback is invoked for every node in the document. Keep the function lightweight — avoid expensive computations or side effects.

Putting it all together

Here is a complete example combining page size, orientation, margins, a dynamic header, and a watermark:
const docDefinition = {
  pageSize: 'A4',
  pageOrientation: 'portrait',
  pageMargins: [40, 80, 40, 60],

  header: function (currentPage, pageCount) {
    return {
      text: 'My Report — Page ' + currentPage + ' of ' + pageCount,
      alignment: 'right',
      margin: [0, 20, 40, 0]
    };
  },

  footer: function (currentPage) {
    return {
      text: 'Confidential — Page ' + currentPage,
      alignment: 'center',
      fontSize: 8
    };
  },

  watermark: { text: 'DRAFT', color: 'red', opacity: 0.15, bold: true },

  content: [
    { text: 'Annual Report 2024', style: 'title' },
    'Lorem ipsum dolor sit amet...'
  ],

  styles: {
    title: { fontSize: 24, bold: true, alignment: 'center', margin: [0, 0, 0, 20] }
  }
};

Next steps

Overview

See how page layout keys fit into the full document definition structure.

Content Nodes

Learn how to build the content array with text, images, tables, lists, and columns.

Build docs developers (and LLMs) love