Section
A section is a run of pages inside a document. Each section paginates on its own: its content starts on a new page and continues onto as many pages as it needs. A document can have several sections with different page sizes or orientations.
Attributes
Section titled “Attributes”| Attribute | Type | Default | Description |
|---|---|---|---|
size |
string | inherit | Page size override: letter, legal, a3, a4, a5, or a custom "200pt 300pt" |
orientation |
string | inherit | portrait or landscape |
margin |
spacing | inherit | Page margin: 48pt, a token such as l, or one to four values like "48pt 24pt" |
background |
color | inherit | Page background color |
title |
string | — | Section title. Accepted, but not used yet: the PDF has no bookmarks |
debug |
boolean | false | Render layout boxes for debugging |
All attributes are optional and inherit from document when not set.
A section holds a layout, a canvas, or both. The one listed first is painted first.
Multiple sections
Section titled “Multiple sections”<document size="letter" margin="48pt"> <section> <layout> <text font-size="14pt">First page</text> </layout> </section> <section> <layout> <text font-size="14pt">Second page</text> </layout> </section></document>L.document({ size: 'letter', margin: '48pt' }, [ L.section(NoAttr, [ L.layout(NoAttr, [ L.text({ fontSize: '14pt' }, ['First page']), ]), ]), L.section(NoAttr, [ L.layout(NoAttr, [ L.text({ fontSize: '14pt' }, ['Second page']), ]), ]),])L.document(DocumentAttr(size='letter', margin='48pt'), [ L.section(NoAttr, [ L.layout(NoAttr, [ L.text(TextAttr(font_size='14pt'), ['First page']) ]) ]), L.section(NoAttr, [ L.layout(NoAttr, [ L.text(TextAttr(font_size='14pt'), ['Second page']) ]) ])])L::document(new DocumentAttr(size: 'letter', margin: '48pt'), [ L::section(NoAttr, [ L::layout(NoAttr, [ L::text(new TextAttr(fontSize: '14pt'), ['First page']), ]), ]), L::section(NoAttr, [ L::layout(NoAttr, [ L::text(new TextAttr(fontSize: '14pt'), ['Second page']), ]), ]),])L.Document(new() { Size = "letter", Margin = "48pt" }, [ L.Section(NoAttr, [ L.Layout(NoAttr, [ L.Text(new() { FontSize = "14pt" }, ["First page"]), ]), ]), L.Section(NoAttr, [ L.Layout(NoAttr, [ L.Text(new() { FontSize = "14pt" }, ["Second page"]), ]), ]),])Mixed page sizes
Section titled “Mixed page sizes”<document> <section size="letter" margin="48pt"> <layout> <text>Letter page content</text> </layout> </section> <section size="a4" margin="40pt"> <layout> <text>A4 page content</text> </layout> </section></document>L.document(NoAttr, [ L.section({ size: 'letter', margin: '48pt' }, [ L.layout(NoAttr, [ L.text(NoAttr, ['Letter page content']), ]), ]), L.section({ size: 'a4', margin: '40pt' }, [ L.layout(NoAttr, [ L.text(NoAttr, ['A4 page content']), ]), ]),])L.document(NoAttr, [ L.section(SectionAttr(size='letter', margin='48pt'), [ L.layout(NoAttr, [ L.text(NoAttr, ['Letter page content']) ]) ]), L.section(SectionAttr(size='a4', margin='40pt'), [ L.layout(NoAttr, [ L.text(NoAttr, ['A4 page content']) ]) ])])L::document(NoAttr, [ L::section(new SectionAttr(size: 'letter', margin: '48pt'), [ L::layout(NoAttr, [ L::text(NoAttr, ['Letter page content']), ]), ]), L::section(new SectionAttr(size: 'a4', margin: '40pt'), [ L::layout(NoAttr, [ L::text(NoAttr, ['A4 page content']), ]), ]),])L.Document(NoAttr, [ L.Section(new() { Size = "letter", Margin = "48pt" }, [ L.Layout(NoAttr, [ L.Text(NoAttr, ["Letter page content"]), ]), ]), L.Section(new() { Size = "a4", Margin = "40pt" }, [ L.Layout(NoAttr, [ L.Text(NoAttr, ["A4 page content"]), ]), ]),])Landscape section
Section titled “Landscape section”<section size="letter" orientation="landscape" margin="72pt"> <layout> <text font-size="18pt">Wide page content</text> </layout></section>L.section({ size: 'letter', orientation: 'landscape', margin: '72pt' }, [ L.layout(NoAttr, [ L.text({ fontSize: '18pt' }, ['Wide page content']), ]),])L.section(SectionAttr(size='letter', orientation='landscape', margin='72pt'), [ L.layout(NoAttr, [ L.text(TextAttr(font_size='18pt'), ['Wide page content']) ])])L::section(new SectionAttr(size: 'letter', orientation: 'landscape', margin: '72pt'), [ L::layout(NoAttr, [ L::text(new TextAttr(fontSize: '18pt'), ['Wide page content']), ]),])L.Section(new() { Size = "letter", Orientation = "landscape", Margin = "72pt" }, [ L.Layout(NoAttr, [ L.Text(new() { FontSize = "18pt" }, ["Wide page content"]), ]),])Section titles
Section titled “Section titles”A section can carry a title. It is accepted and changes nothing in the PDF yet: Lpdf does not write a bookmarks outline, so a long document opens with an empty bookmarks panel.
<document size="a4" margin="48pt"> <section title="Introduction"> <layout> <text font-size="20pt">Introduction</text> </layout> </section> <section title="Results"> <layout> <text font-size="20pt">Results</text> </layout> </section></document>L.document({ size: 'a4', margin: '48pt' }, [ L.section({ title: 'Introduction' }, [ L.layout(NoAttr, [ L.text({ fontSize: '20pt' }, ['Introduction']), ]), ]), L.section({ title: 'Results' }, [ L.layout(NoAttr, [ L.text({ fontSize: '20pt' }, ['Results']), ]), ]),])L.document(DocumentAttr(size='a4', margin='48pt'), [ L.section(SectionAttr(title='Introduction'), [ L.layout(NoAttr, [ L.text(TextAttr(font_size='20pt'), ['Introduction']) ]) ]), L.section(SectionAttr(title='Results'), [ L.layout(NoAttr, [ L.text(TextAttr(font_size='20pt'), ['Results']) ]) ])])L::document(new DocumentAttr(size: 'a4', margin: '48pt'), [ L::section(new SectionAttr(title: 'Introduction'), [ L::layout(NoAttr, [ L::text(new TextAttr(fontSize: '20pt'), ['Introduction']), ]), ]), L::section(new SectionAttr(title: 'Results'), [ L::layout(NoAttr, [ L::text(new TextAttr(fontSize: '20pt'), ['Results']), ]), ]),])L.Document(new() { Size = "a4", Margin = "48pt" }, [ L.Section(new() { Title = "Introduction" }, [ L.Layout(NoAttr, [ L.Text(new() { FontSize = "20pt" }, ["Introduction"]), ]), ]), L.Section(new() { Title = "Results" }, [ L.Layout(NoAttr, [ L.Text(new() { FontSize = "20pt" }, ["Results"]), ]), ]),])Content always goes in a section. A layout placed directly inside document is an error.