PDFium Delphi Component Docs

FPdfLayout unit

Builds measurable flow-layout plans with page furniture, columns, cross-page tables, links, reusable nodes, markup input, and tagged-PDF semantics

Exceptions and enumerations

TypeValues or purpose
EPdfLayoutErrorException raised for invalid layout input, exceeded limits, and inconsistent semantic structure
TPdfLayoutAlignmentplaLeft, plaCenter, plaRight, plaJustify
TPdfLayoutVerticalAlignmentptvaTop, ptvaMiddle, ptvaBottom
TPdfLayoutCommandKindplcText, plcRule, plcImage, plcPageXObject, plcCachedNode, plcLink, plcRectangle
TPdfLayoutItemKindpliText, pliSpacer, pliRule, pliImage, pliPageXObject, pliPageBreak, pliCachedNode, pliLink, pliSemanticNode, pliTable
TPdfLayoutSemanticRoleplsrArtifact, plsrParagraph, plsrHeading1, plsrHeading2, plsrHeading3, plsrHeading4, plsrHeading5, plsrHeading6, plsrList, plsrListItem, plsrListLabel, plsrListBody, plsrTable, plsrTableRow, plsrTableHeader, plsrTableData, plsrFigure, plsrCaption, plsrLink, plsrSection, plsrDivision, plsrSpan
TPdfLayoutTableScopepltsNone, pltsRow, pltsColumn, pltsBoth
TPdfLayoutListNumberingplnNone, plnDisc, plnCircle, plnSquare, plnDecimal, plnUpperRoman, plnLowerRoman, plnUpperAlpha, plnLowerAlpha
TPdfLayoutGridTrackKindplgtkFixed, plgtkFraction, plgtkAuto
TPdfMarkupFormatpmfMarkdown, pmfHtml

Layout records

TypePublic members
TPdfLayoutSemanticsRole, ParentID, ElementID, AlternateText, ActualText, Language, HeaderIDs, TableScope, ColumnSpan, RowSpan, ListNumbering, Artifact, Paragraph, Figure
TPdfLayoutTextStyleFontName, FontSize, Color, Alpha, LineHeight, Alignment, KeepTogether, BreakLongWords, SpaceBefore, SpaceAfter, FirstLineIndent, Default
TPdfLayoutConstraintsKeepTogether, KeepWithNext, PageBreakBefore, PageBreakAfter, OrphanLines, WidowLines, Default
TPdfLayoutPageSettingsWidth, Height, MarginLeft, MarginTop, MarginRight, MarginBottom, HeaderHeight, FooterHeight, A4, Letter
TPdfLayoutRectLeft, Top, Width, Height
TPdfLayoutGridTrackKind, Value, Minimum, Maximum, MeasuredContent
TPdfLayoutGridTracksDynamic array of TPdfLayoutGridTrack
TPdfLayoutGridSizesDynamic array of resolved track sizes
TPdfLayoutTableOptionsCellPadding, BorderWidth, BorderColor, BorderAlpha, RepeatHeaderRows, RepeatFooterRows, FooterRowCount, AllowRowSpanContinuation, MaxContinuationRegions, ContinuationBefore, ContinuationAfter, ContinuationStyle, Default
TPdfLayoutTableTextRunText, Style
TPdfLayoutTableTextRunsDynamic array of TPdfLayoutTableTextRun
TPdfMarkupOptionsBaseStyle, HeadingScale, MaxInputCharacters, MaxNodes, Default
TPdfLayoutSemanticElementSemantics, ParentElementIndex
TPdfLayoutSemanticElementsDynamic array of TPdfLayoutSemanticElement
TPdfLayoutCommandKind, PageNumber, Bounds, Text, FontName, FontSize, Color, Alpha, Alignment, Thickness, FileName, Uri, Source, SourcePageIndex, SemanticElementIndex, MarkedContentID, AnnotationIndex
TPdfLayoutCommandsDynamic array of TPdfLayoutCommand
TPdfLayoutPlanPageSettings, PageCount, Commands, SemanticElements, TextLineCount, RuleCount, RectangleCount, ImageCount, PageXObjectCount, CachedNodeCount, LinkCount, TaggedContentCount, ArtifactCount, MeasuredTextCount, TotalPageReferenceCount, ReservedPageDigits, CacheHitCount, CacheMissCount, ReusedXObjectCount, ColumnCount, ColumnGap

Layout classes

TypePublic members
TPdfLayoutMeasurerMeasureTextWidth, CacheIdentity
TPdfLayoutItemKind
TPdfLayoutTableCellText, Uri, Style, VerticalAlignment, AddTextRun, TextRuns, SetImage, ColumnSpan, RowSpan, Header, ElementID, HeaderIDs, Scope
TPdfLayoutTableRowAddCell, Cells, Header, AllowSplit, MinimumHeight, KeepWithPrevious
TPdfLayoutTableCreate, Destroy, AddRow, AddSubtotalRow, SetCaption, Columns, Rows, Options, Caption, CaptionStyle, ElementID, ParentID
TPdfLayoutPagedPlanCreate, Destroy, ClearPageCache, MaterializePage, Reset, Summary, CommandCount, StorageByteCount, SourceCount, Completed, the MaxCommandCount, MaxStorageBytes, MaxPageCommands, MaxSourceCount, and MaxCachedPages budgets, and the CachedPageCount, CacheHitCount, CacheMissCount, and PeakCachedPageCount cache statistics
TPdfLayoutDocumentCreate, Destroy, Clear, AddText, AddSpacer, AddRule, AddImage, AddPageXObject, AddCachedNode, AddLink, AddSemanticNode, SetLastItemSemantics, SetLastItemConstraints, AddTable, AddPageBreak, LoadMarkup, InvalidateCache, BuildPlan, BuildPagedPlan, PageSettings, HeaderText, FooterText, HeaderStyle, FooterStyle, ReservedPageDigits, ColumnCount, ColumnGap, Items
TPdfLayoutCachedNodeCreate, Destroy, Invalidate, BeginEmission, EndEmission, Content, Width, Height, Built

Pagination constraints

Call SetLastItemConstraints after adding any visible flow item to keep it together, keep it with the start of the next item, or force a physical page break before or after it

OrphanLines is the minimum number of paragraph lines retained at the bottom of a region and WidowLines is the minimum placed at the top of the following region; both default to one to preserve existing pagination

Constraints apply equally to paragraph, link, list, figure, and table-role items, while semantic-only containers have no geometry and therefore reject pagination constraints

A pliTable item accepts only PageBreakBefore and PageBreakAfter; row splitting and table-start retention are controlled by the table model

The planner caches wrapped lines during a build, so keep-with-next prediction and final command emission do not measure the same text twice

Paged command plans

Create TPdfLayoutPagedPlan over a dedicated seekable and resizable TStream, then call BuildPagedPlan or pass it to TPdf.GeneratePagedLayout

The planner serialises commands immediately, releases each completed wrapped-text result, and leaves Plan.Commands empty while retaining page settings, semantic elements, counts, and stable page totals in the summary

Body commands and later header or footer commands are indexed as linked page segments, so MaterializePage restores the complete page without scanning commands for other pages

MaxCachedPages bounds only the page arrays retained by the plan; callers that keep returned arrays extend their lifetime, and PDFium retains native authored pages until the destination document is saved or closed

The storage format is private session state rather than a portable file format, the stream must not be shared or modified externally, and source objects referenced by page XObjects or cached nodes must outlive the paged plan

Use TPdfRandomAccessStore when commands should remain in memory up to a selected threshold and spill to delete-on-close temporary storage afterwards

Cross-page tables

Create TPdfLayoutTable with fixed, fractional, or content-sized grid tracks, add rows and cells, then call AddTable; the document stores an owned snapshot so later caller mutations cannot invalidate an existing plan cache

Header rows must be contiguous at the start of the table and repeat after a page or column transition when RepeatHeaderRows is true; header row spans cannot extend into body rows

Set RepeatFooterRows to True (with FooterRowCount specifying the number of trailing rows, or 0 to repeat the final row) to repeat table footer or subtotal rows at the bottom of every page or column region; each cell also supports vertical alignment (VerticalAlignment: ptvaTop, ptvaMiddle, ptvaBottom) within its resolved row or span height

A body row can split when AllowSplit is true; by default, transitive row-spanning groups move as one atomic unit and cells in an ordinary split row share the same line band, padding, and border geometry

Set AllowRowSpanContinuation to True to let a row-spanning group continue across page or column regions; the planner distributes extra span height across its rows and chooses cuts that intersect neither a text line nor an image

AllowSplit=False remains an atomic-row constraint; incompatible row constraints or an atomic block that cannot fit a fresh region raise EPdfLayoutError instead of clipping or repeating content

Captions stay with the initial header block and the minimum start of the first body group; repeated headers reuse the same original header elements

The planner emits one Table element, optional Caption, TR children, and TH or TD cells regardless of page count; repeated header commands reuse the original semantic indexes, and TD cells receive overlapping header IDs automatically unless explicit valid IDs are supplied

Table borders are artifact plcRectangle commands rendered through native PDFium path objects, while caption and cell text remain tagged content

Mixed text and image cells

AddTextRun appends inline text after the cell's original Text; each run has its own font, font size, color, alpha, line height and long-word breaking policy

Mixed text wraps using measured widths, preserves UTF-16 surrogate pairs when breaking a long word and emits separate native text objects with a shared baseline; horizontal alignment comes from the cell's base Style

Run-level paragraph spacing and keep-together flags do not introduce additional paragraph blocks; use separate rows or ordinary layout items when those constraints are required

SetImage configures one file-backed image per cell, positioned above its text at the left padding; another call replaces that image

Provide an explicit positive height and a width that fits the inner cell width; a width of zero uses the entire inner width, and the caller controls the image's aspect ratio through the supplied dimensions

The image is indivisible during continuation and is emitted once at its original position; its file must remain available until generation, and a missing file or unsupported image causes generation to roll back appended pages

A nonempty alternate description is required; the image becomes a Figure child of its original TH or TD, while all text fragments remain associated with that cell

Across pages, the original TH or TD receives the continued marked-content references and retains its RowSpan, ColumnSpan and header associations; no duplicate logical cell is created

Subtotals and continuation labels

AddSubtotalRow creates an atomic body row using the caller's label, formatted value and style; for multiple columns the label spans all but the final value column

The helper sets KeepWithPrevious=True so a subtotal does not become an isolated first row on a continuation; values are supplied by the caller and no numeric aggregation is performed

ContinuationAfter is shown at the end of a region that continues, and ContinuationBefore is shown after any repeated headers in the following region

Both labels default to empty, use ContinuationStyle, must fit on one line and reserve their own height; the first region has no before label and the final region has no after label

Labels and borders are artifacts, leaving the semantic table hierarchy unchanged; page placeholders such as {page} and {pages} use the ordinary layout text resolver

Advanced table declarations and limits

procedure TPdfLayoutTableCell.AddTextRun(const Text: WideString;
  const Style: TPdfLayoutTextStyle);

procedure TPdfLayoutTableCell.SetImage(const FileName: string;
  Width, Height: Single; const AlternateText: WideString);

function TPdfLayoutTable.AddSubtotalRow(const LabelText, ValueText: WideString;
  const Style: TPdfLayoutTextStyle): TPdfLayoutTableRow;

Use TPdfLayoutTableOptions.Default before overriding options; AllowRowSpanContinuation defaults to False and MaxContinuationRegions defaults to 10,000 page or column regions, with a configurable ceiling of 100,000

Tables retain the 256-column, 100,000-row and 100,000-semantic-element limits; total cell text is limited to 8,000,000 UTF-16 code units

A mixed-text cell accepts at most 1,024 appended runs, 1,000,000 UTF-16 code units, 100,000 lines and 100,000 fragments; an individual character or a word with long-word breaking disabled that exceeds the available width is rejected

A continued row group is limited to 10,000 cells; region budgets and bounded cut searches prevent unbounded pagination, and images must fit the available body region after headers, labels and padding

The owned table snapshot and plan cache include run styles, image dimensions, alternate text, subtotal retention and continuation settings; later changes to the caller's table do not alter that snapshot

Top-level routines

RoutineDescription
ResolveLayoutTextExpands page-number placeholders using the reserved digit width
PdfLayoutSemanticRoleNameReturns the tagged-PDF structure name for a semantic role
BuildTaggedLayoutPdfApplies a completed layout plan and tagged structure to source PDF bytes
ResolvePdfLayoutGridTracksResolves fixed, fractional, and content-sized grid tracks within the available width

See Also