2. A document is an array of blocks
Before this: You have generated hello.pdf.
There is no cursor, no moveTo, no manual page tracking. You hand pdfnative an ordered array of blocks and it lays them out top to bottom, breaking pages as needed.
blocks: [
{ type: 'heading', text: 'Ingredients', level: 2 },
{ type: 'list', items: ['Flour', 'Water', 'Salt'], style: 'bullet' },
{ type: 'spacer', height: 20 },
{ type: 'pageBreak' },
{ type: 'paragraph', text: 'Now the methodβ¦' },
]
That is the whole mental model. Reordering the array reorders the document; there is nothing else to keep in sync.
The 13 block types
Start with the first four. The rest are the same idea with different fields.
headingβtext,level(1, 2 or 3)paragraphβtextlistβitems(nestable) andstyle:'bullet'or'numbered'. Both are required.tableβ the next pagespacerβheightin pointspageBreakβ no fieldsimage,barcode,svg,chartβ visual contentlink,toc,formFieldβ interactive content
Automatic page breaks
You do not need pageBreak to get a multi-page document. Add fifty paragraphs and you get however many pages that takes. Use pageBreak only when you want a break at a specific point.
You should now be able to build a multi-page document by composing blocks, without thinking about page geometry.
Tip: Alt + β / β moves between steps.