Skip to main content

Module layout

Module layout 

Source
Expand description

§Page-Aware Layout Engine

This is the heart of Forme and the reason it exists.

§The Problem With Every Other Engine

Most PDF renderers do this:

  1. Lay out all content on an infinitely tall canvas
  2. Slice the canvas into pages
  3. Try to fix the things that broke at slice points

Step 3 is where everything falls apart. Flexbox layouts collapse because the flex algorithm ran on the pre-sliced dimensions. Table rows get split in the wrong places. Headers don’t repeat. Content gets “mashed together.”

§How Forme Works

Forme never creates an infinite canvas. The layout algorithm is:

  1. Open a page with known dimensions and remaining space
  2. Place each child node. Before placing, ask: “does this fit?”
  3. If it fits: place it, reduce remaining space
  4. If it doesn’t fit and is unbreakable: start a new page, place it there
  5. If it doesn’t fit and is breakable: place what fits, split the rest to a new page, and RE-RUN flex layout on both fragments
  6. For tables: when splitting, clone the header rows onto the new page

The key insight in step 5: when a flex container splits across pages, BOTH fragments get their own independent flex layout pass. This is why react-pdf’s flex breaks on page wrap — it runs flex once on the whole container and then slices, so the flex calculations are wrong on both halves. We run flex AFTER splitting.

Modules§

audit
Post-render content audit (opt-in, RenderOptions::audit_content).
flex
Flex Layout Utilities
grid
CSS Grid Layout
page_break
Page Break Decisions

Structs§

BookmarkEntry
A bookmark entry collected during layout.
ElementInfo
Layout metadata for a single positioned element (hierarchical).
ElementStyleInfo
Serializable snapshot of ResolvedStyle for the inspector panel.
LayoutElement
A positioned element on a page.
LayoutEngine
The main layout engine.
LayoutInfo
Complete layout metadata for all pages.
LayoutPage
A fully laid-out page ready for PDF serialization.
PageInfo
Layout metadata for a single page.
PositionedGlyph
TextLine

Enums§

DrawCommand
What to actually draw for this element.
FormFieldType
Configuration for an interactive PDF form field.

Constants§

PAGE_NUMBER_SENTINEL
Sentinel character for {{pageNumber}} placeholder. A single char that is atomic (can’t be split by line breaking), measured as the width of “00”, and recognized by the PDF serializer for replacement.
TOTAL_PAGES_SENTINEL
Sentinel character for {{totalPages}} placeholder.