Document, build elements
with the page factories, add them to the page or to a container, and call build. Elements
flow top to bottom by default, or sit at exact coordinates when given a position.
The Document class
Construct aDocument with an optional DocumentOptions object.
"A4" | "Letter" | "Legal" | "Custom"
The page format. Use
"Custom" together with custom_dimensions for any other size.{ width: number; height: number }
Width and height in points, used when you need a size outside the named formats.
number | MarginValues
A single number for all sides, or per side values.
boolean
Enables markdown parsing on text content. Individual text elements can override this.
Document methods
create_page returns a fresh page and optionally applies a theme to it. add_page appends
another page to the document. set_theme applies a theme document wide. load_font_sync
registers a font by name, with variable: true to enable weight instancing for a custom
variable font. load_image_sync registers an image by name so it can be referenced from
page.image.
The build pipeline
build runs the engine in three passes. Measure computes each element’s intrinsic size from
font metrics. Layout assigns positions from the page margin and header zone. Render draws
every element in z index order.
build is prepare_pdf followed by render_to. The split exists so a caller can measure
before rendering, which is how the Doc API paginates.
Page factories
The page builds elements but does not place them. Add what you build withpage.add or a
container’s add.
header_container and footer_container are idempotent. Calling either again returns the
existing zone rather than creating a new one.get_content_width() and get_content_height(), which give the
usable area inside the margins. They are handy for sizing full width containers and tables.
A complete example
Next steps
Elements
Text, rectangles, images, overlay children, and z index ordering.
Layout
Group children with flow and flex containers.
Themes
Centralize named colors and apply defaults by element type.
Tables
Build rows and columns with the low level table factory.