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.
Every piece of text in pdfmake is ultimately a node in the content array. You can pass a bare string for plain paragraphs, or wrap it in an object to attach formatting properties. The two forms are completely interchangeable — pdfmake normalises plain strings internally.
Text node forms
The simplest content array contains plain strings:
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'
]
};
Switch to an object node whenever you need to attach properties:
const docDefinition = {
content: [
{
text: 'Paragraphs can also be styled without using named-styles (this one sets fontSize to 25)',
fontSize: 25
},
{
text: 'This paragraph sets fontSize to 8 and italics to true',
fontSize: 8,
italics: true
}
]
};
Font properties
Size and family
fontSize accepts a number in points. font (alias fontFamily) selects a registered font name, e.g. 'Roboto'.
Weight and style
bold: true and italics: true select the bold and italic variants of the current font.
Color and background
color sets the foreground text color. background sets a highlight color or a pattern array.
Opacity
opacity accepts 0–1 to make text semi-transparent.
const docDefinition = {
content: [
// Opacity levels
{ text: 'Hello World', opacity: 0.8 },
{ text: 'Hello World', opacity: 0.6 },
{ text: 'Hello World', opacity: 0.4 },
{ text: 'Hello World', opacity: 0.2 },
// Background highlight
{ text: 'Highlighted text', fontSize: 18, background: 'yellow' },
// Background pattern
{ text: 'Text background pattern', background: ['stripe45d', 'gray'] }
],
patterns: {
stripe45d: {
boundingBox: [1, 1, 4, 4],
xStep: 3,
yStep: 3,
pattern: '1 w 0 1 m 4 5 l s 2 0 m 5 3 l s'
}
}
};
Text decoration
Use decoration to add lines to text. Combine it with decorationStyle and decorationColor for precise control.
Choose a decoration type
Set decoration to 'underline', 'lineThrough', or 'overline'.
Pick a decoration style
Set decorationStyle to 'solid' (default), 'dashed', 'dotted', 'double', or 'wavy'.
Apply a color
Set decorationColor to any CSS-compatible color string.
Set thickness (optional)
Set decorationThickness to a number in points.
const docDefinition = {
content: [
{ text: 'Underline decoration', decoration: 'underline' },
{ text: 'Line Through decoration', decoration: 'lineThrough' },
{ text: 'Overline decoration', decoration: 'overline' },
{ text: 'Dashed style', decoration: 'underline', decorationStyle: 'dashed' },
{ text: 'Dotted style', decoration: 'underline', decorationStyle: 'dotted' },
{ text: 'Wavy style', decoration: 'underline', decorationStyle: 'wavy', decorationThickness: 3 },
{ text: 'Using colors', decoration: 'underline', decorationColor: 'blue' },
{ text: 'Using colors', decoration: 'lineThrough', decorationColor: 'red' }
]
};
Alignment and spacing
| Property | Values | Description |
|---|
alignment | 'left', 'center', 'right', 'justify' | Horizontal alignment |
lineHeight | number | Multiplier relative to font size |
characterSpacing | number | Extra space between characters (points) |
const docDefinition = {
content: [
{ text: 'Justified paragraph', alignment: 'justify', lineHeight: 1.5 },
{ text: 'Centered heading', alignment: 'center', fontSize: 18 },
{ text: 'Wide tracking', characterSpacing: 3 }
]
};
Superscript and subscript
Set sup: true to raise text and sub: true to lower it. Both properties also reduce the font size automatically.
const docDefinition = {
content: [
{
text: [
'Hello World.',
{ text: '1, 2', sup: true },
" Let's continue our sentence. Notice the leading space."
]
},
{
text: [
'Hello',
{ text: '1, 2', sub: true },
' World'
]
}
]
};
Decorations also work on superscript and subscript nodes. Combine sup: true with decoration: 'underline' for annotated references.
Word break and whitespace
By default, pdfmake strips leading spaces and breaks long words at word boundaries. Two properties override this behaviour:
const docDefinition = {
content: [
// Preserve leading spaces (useful for code-style text)
{ text: ' This is a paragraph with preserved leading spaces.', preserveLeadingSpaces: true },
{ text: '{', preserveLeadingSpaces: true },
{ text: ' "sample": {', preserveLeadingSpaces: true },
{ text: ' "json": "nested"', preserveLeadingSpaces: true },
{ text: ' }', preserveLeadingSpaces: true },
{ text: '}', preserveLeadingSpaces: true },
// Break characters mid-word when they won't fit
{
text: 'BreakAll\n"LineBreakBehaviour" "ForATextWithVeryVery" "LongLongWords"',
fontSize: 30,
wordBreak: 'break-all'
}
]
};
Font features (OpenType)
fontFeatures accepts an array of OpenType feature tags. Only fonts that include the requested features will use them.
const docDefinition = {
content: [
{ text: 'Hello World 1234567890', fontFeatures: ['smcp'] }, // small caps
{ text: 'Hello World 1234567890', fontFeatures: ['c2sc'] }, // capitals to small caps
{ text: 'Hello World 1234567890', fontFeatures: ['onum'] }, // old-style numerals
{ text: 'Hello World 1234567890', fontFeatures: ['onum', 'c2sc'] }
]
};
Inline styles
Compose mixed-format runs by setting text to an array. Each element can be a string or an object with its own properties. Child properties override the parent.
const docDefinition = {
content: [
{
text: [
'This is ',
{ text: 'bold', bold: true },
' and this is ',
{ text: 'italic', italics: true },
' text in the same paragraph.'
]
}
]
};
Named styles
Define reusable style objects in the styles dictionary and reference them by name using style. Multiple styles can be applied as an array — later entries take precedence.
const docDefinition = {
content: [
{
text: 'This is a header, using header style',
style: 'header'
},
'Lorem ipsum dolor sit amet ...',
{
text: 'Subheader 1 - using subheader style',
style: 'subheader'
},
{
text: 'Multiple styles applied: quote overrides italics, small overrides fontSize',
style: ['quote', 'small']
}
],
styles: {
header: {
fontSize: 18,
bold: true
},
subheader: {
fontSize: 15,
bold: true
},
quote: {
italics: true
},
small: {
fontSize: 8
}
}
};
When multiple styles define the same property, the last style in the array wins. In the example above, small.fontSize (8) overrides quote’s inherited font size.
defaultStyle
defaultStyle sets document-wide property defaults that apply to every node unless overridden. It is the lowest-priority style in the cascade.
const docDefinition = {
content: [
'This paragraph inherits 12 pt Roboto from defaultStyle.',
{ text: 'This one overrides color to red.', color: 'red' }
],
defaultStyle: {
fontSize: 12,
font: 'Roboto'
}
};
defaultStyle is useful for setting columnGap, alignment: 'justify', or a base lineHeight that applies throughout the document without repeating the property on every node.