Doc is a list of pages, and each page is a list of content blocks. You describe what the
document contains, set role styles once, and call build. Pagination, headers, footers, and
font loading are handled for you.
Under the hood Doc compiles its block tree down to the low level Document and Page
element API and then renders. It adds no separate engine, so anything Doc produces could
also be built by hand with Document.
Constructor
DocOptions extends DocumentOptions and adds a few document level fields:
Inner inset added on top of
margin. Margin and padding are summed into the page content
inset.A document wide header. See Headers and footers.
A document wide footer. See Headers and footers.
Flow content across pages automatically. Set it to
false to keep each page literal.Markdown parsing on plain string text is on by default in
Doc. Plain strings honor
**bold**, *italic*, ~~strike~~, and $inline math$. Structured inline nodes always
format regardless of that flag. See Inline content.Methods
Assigns a default style per role. Block level
style merges on top. See
Styling.Sets the document wide header.
Sets the document wide footer.
Registers a custom font by name for use in
font_family. Pass variable: true to enable
weight instancing. See Fonts and weights.Registers an image by name so a block can reference it by name instead of a path.
Adds a page and returns a
DocPage. The optional config sets a per page header and footer.Renders the document and writes it to disk. Always awaited.
DocPage.content
content flattens arrays, so a component that returns Block[] can be spread inline. This
makes reusable blocks composable without wrapping them in a group.
A complete example
Next
Blocks
Every block type, from headings and paragraphs to tables, charts, and groups.
Styling
Role styles, block level overrides, and the style properties that matter for documents.
Headers and footers
Static, dynamic, and raw draw headers and footers, document wide or per page.
Inline content
Strong, em, strike, links, inline code, and inline formulas, with markdown shortcuts.