Layout
layout is the flow container inside a section. Elements stack vertically and paginate automatically — when content overflows a page, it continues on the next.
<lpdf version="1"> <document size="letter" margin="48pt"> <section> <layout> <stack gap="16pt"> <text font-size="18pt">Title</text> <divider/> <text>Body text goes here.</text> </stack> </layout> </section> </document></lpdf>L.document({ size: 'letter', margin: '48pt' }, [ L.section(NoAttr, [ L.layout(NoAttr, [ L.stack({ gap: '16pt' }, [ L.text({ fontSize: '18pt' }, ['Title']), L.divider(NoAttr), L.text(NoAttr, ['Body text goes here.']), ]), ]), ]),])L.document(DocumentAttr(size='letter', margin='48pt'), [ L.section(NoAttr, [ L.layout(NoAttr, [ L.stack(StackAttr(gap='16pt'), [ L.text(TextAttr(font_size='18pt'), ['Title']), L.divider(NoAttr), L.text(NoAttr, ['Body text goes here.']) ]) ]) ])])L::document(new DocumentAttr(size: 'letter', margin: '48pt'), [ L::section(NoAttr, [ L::layout(NoAttr, [ L::stack(new StackAttr(gap: '16pt'), [ L::text(new TextAttr(fontSize: '18pt'), ['Title']), L::divider(NoAttr), L::text(NoAttr, ['Body text goes here.']), ]), ]), ]),])L.Document(new() { Size = "letter", Margin = "48pt" }, [ L.Section(NoAttr, [ L.Layout(NoAttr, [ L.Stack(new() { Gap = "16pt" }, [ L.Text(new() { FontSize = "18pt" }, ["Title"]), L.Divider(NoAttr), L.Text(NoAttr, ["Body text goes here."]), ]), ]), ]),])Elements
Section titled “Elements”| Element | Purpose |
|---|---|
stack |
Children top to bottom, with a gap between them |
flank |
One row: every child keeps its own width except one, which fills the rest |
split |
Two children side by side, at opposite edges or in equal halves |
cluster |
Wrapping inline row |
text |
Text block with optional span children |
divider |
Horizontal or vertical rule |
frame |
Atomic box around one child — will not split across pages |
img |
Image asset |
grid |
Equal columns, filled left to right |
table |
Table with rows, cells, and repeating header |
barcode |
QR, Code128, or EAN-13 barcode |
link |
Clickable hyperlink wrapper |
field |
Interactive PDF form element |
Pagination rules
Section titled “Pagination rules”stack— splits between childrentable— splits between rows, and repeats thetheadrow on each pagecluster,grid— split between lines and rows: a row is never cut in twotext— splits between linesflank,split,frame— atomic; move whole to the next page if they don’t fit- Setting
heighton a box (a length,fillorfull) also stops it splitting
Pinned regions
Section titled “Pinned regions”region pins content to the top or bottom of the content area, reserving space from the flow. Useful for per-page headers and footers. It is only allowed directly inside layout, and a page can have one per pin.
<layout> <region pin="top"> <flank> <text font-size="9pt">My Company</text> <text font-size="9pt" align="right">Confidential</text> </flank> </region> <region pin="bottom"> <text font-size="9pt" align="center" color="#aaaaaa">Page {page} of {pages}</text> </region> <stack gap="16pt"> <text font-size="18pt">Main content</text> <text>Body text flows here, between the two regions.</text> </stack></layout>L.layout(NoAttr, [ L.region({ pin: 'top' }, [ L.flank(NoAttr, [ L.text({ fontSize: '9pt' }, ['My Company']), L.text({ fontSize: '9pt', align: 'right' }, ['Confidential']), ]), ]), L.region({ pin: 'bottom' }, [ L.text({ fontSize: '9pt', align: 'center', color: '#aaaaaa' }, ['Page {page} of {pages}']), ]), L.stack({ gap: '16pt' }, [ L.text({ fontSize: '18pt' }, ['Main content']), L.text(NoAttr, ['Body text flows here, between the two regions.']), ]),])L.layout(NoAttr, [ L.region(RegionAttr(pin='top'), [ L.flank(NoAttr, [ L.text(TextAttr(font_size='9pt'), ['My Company']), L.text(TextAttr(font_size='9pt', align='right'), ['Confidential']) ]) ]), L.region(RegionAttr(pin='bottom'), [ L.text(TextAttr(font_size='9pt', align='center', color='#aaaaaa'), ['Page {page} of {pages}']) ]), L.stack(StackAttr(gap='16pt'), [ L.text(TextAttr(font_size='18pt'), ['Main content']), L.text(NoAttr, ['Body text flows here, between the two regions.']) ])])L::layout(NoAttr, [ L::region(new RegionAttr(pin: 'top'), [ L::flank(NoAttr, [ L::text(new TextAttr(fontSize: '9pt'), ['My Company']), L::text(new TextAttr(fontSize: '9pt', align: 'right'), ['Confidential']), ]), ]), L::region(new RegionAttr(pin: 'bottom'), [ L::text(new TextAttr(fontSize: '9pt', align: 'center', color: '#aaaaaa'), ['Page {page} of {pages}']), ]), L::stack(new StackAttr(gap: '16pt'), [ L::text(new TextAttr(fontSize: '18pt'), ['Main content']), L::text(NoAttr, ['Body text flows here, between the two regions.']), ]),])L.Layout(NoAttr, [ L.Region(new() { Pin = "top" }, [ L.Flank(NoAttr, [ L.Text(new() { FontSize = "9pt" }, ["My Company"]), L.Text(new() { FontSize = "9pt", Align = "right" }, ["Confidential"]), ]), ]), L.Region(new() { Pin = "bottom" }, [ L.Text(new() { FontSize = "9pt", Align = "center", Color = "#aaaaaa" }, ["Page {page} of {pages}"]), ]), L.Stack(new() { Gap = "16pt" }, [ L.Text(new() { FontSize = "18pt" }, ["Main content"]), L.Text(NoAttr, ["Body text flows here, between the two regions."]), ]),])| Attribute | Type | Default | Description |
|---|---|---|---|
pin |
string | — | Required. top or bottom. left and right pass validation but are not implemented yet |
page |
string | each |
Which pages show the region: each, first, last, odd, even, or a range like 2-last |
debug |
boolean | false | Render the region’s box for debugging |
In the text of a region, {page} becomes the page number and {pages} the total number of pages. Use them for “Page 2 of 5” footers. They are only replaced inside a region.
<region pin="top" page="first"> <text font-size="22pt">Cover page title</text></region>L.region({ pin: 'top', page: 'first' }, [ L.text({ fontSize: '22pt' }, ['Cover page title']),])L.region(RegionAttr(pin='top', page='first'), [ L.text(TextAttr(font_size='22pt'), ['Cover page title'])])L::region(new RegionAttr(pin: 'top', page: 'first'), [ L::text(new TextAttr(fontSize: '22pt'), ['Cover page title']),])L.Region(new() { Pin = "top", Page = "first" }, [ L.Text(new() { FontSize = "22pt" }, ["Cover page title"]),])