Home  β€Ί  Learn  β€Ί  The block model

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.

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.