Composing documents
Describe content as blocks and let the layout engine place it. No browser, no print pipeline, no font installed on the host.
Content blocks
const { document, report } = await Pdf.create( [ { kind: 'heading', level: 1, text: 'Quarterly report' }, { kind: 'paragraph', text: 'Revenue rose by eleven per cent.' }, { kind: 'list', items: ['Subscriptions grew', 'Hardware was flat'] }, ], font,)Order is reading order. The engine decides the measure, the leading, where lines break, where pages break, and keeps a heading with the section under it.
Page and columns
await Pdf.create(content, font, { pageSize: 'a4', margin: 56, columns: 2, gutter: 18, bodySize: 10, headingSizes: [22, 16, 13], title: 'Quarterly report',})Text fills the first column, then the next, then the first column of a new page. Widows and orphans are controlled, and a heading that cannot fit with the start of its section moves rather than being stranded at the foot of a column.
The typeface
The font is required and embedded. A document set in a font nobody embedded looks like whatever the reader has installed, which is the one thing a PDF exists to prevent.
It is subset to the characters actually drawn. 515 KB of Roboto becomes a 14.5 KB subset for the two dozen glyphs a short document uses. Text that fits WinAnsi gets a simple font; text that does not gets a Type0 font with /Identity-H, chosen from the content rather than asked of you.
Reading the report
console.log(report.pages) // 2console.log(report.lines) // 44console.log(report.baseFont) // 'OEDTIL+Roboto-Regular'console.log(report.composite) // falseconsole.log(report.approximated) // 1console.log(report.missing) // ['中', '文']missing is not a warning to ignore
missing array is the only result safe to skip checking. approximated counts blocks drawn as plain text because their structure is not drawn: lists without bullets, tables without rules.One face per document today. Bold and italic need a second and third embedded font, which is the next piece of work here.