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
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
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, 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, AllowRowSpanContinuation, MaxContinuationRegions, ContinuationBefore, ContinuationAfter, ContinuationStyle, Default
TPdfLayoutTableTextRunText, Style
TPdfLayoutTableTextRunsA dynamic array containing TPdfLayoutTableTextRun values
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, 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, whilst 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 whilst 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

A body row may split with AllowSplit set to true; by default, transitive row-span groups move together as atomic units, and an ordinary split row gives all cells the same line band, padding and border geometry

Enable AllowRowSpanContinuation with True to continue a row-span group across page or column regions; the planner spreads extra spanning height across the rows and finds cuts that avoid text lines and images

AllowSplit=False still makes a row atomic; incompatible constraints or an atomic block too large for a fresh region raise EPdfLayoutError, rather than clipping or repeating its contents

Captions remain with the initial header block and the minimum opening of the first body group; subsequent headers reuse the 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, whilst caption and cell text remain tagged content

Cells containing styled text and images

AddTextRun appends inline content after a cell's initial Text; each run selects its own font, size, colour, alpha, line height and long-word splitting policy

Mixed text wraps to measured widths, keeps UTF-16 surrogate pairs intact when splitting a long word and produces separate native text objects on a common baseline; the cell's base Style determines horizontal alignment

Paragraph spacing and keep-together settings on a run do not create extra paragraph blocks; use separate rows or regular layout items for those constraints

SetImage assigns one file-backed image to a cell, above its text at the left padding; calling it again replaces that image

Supply a positive height and a width that fits inside the cell; zero width fills its inner width, and the supplied dimensions determine aspect ratio

Continuation cannot split the image, which appears once at its original position; its file must remain accessible until generation, and missing or unsupported images cause appended pages to be rolled back

The alternate description must not be empty; a Figure child is added beneath the original TH or TD, and text fragments remain linked to that same cell

Across page breaks, the original TH or TD collects continued marked-content references, retaining RowSpan, ColumnSpan and header associations without creating a second logical cell

Subtotal rows and continuation labels

AddSubtotalRow makes an atomic body row using the supplied label, formatted value and style; in a multicolumn table, the label spans every column except the last value column

The helper enables KeepWithPrevious=True to keep a subtotal from standing alone at the start of a continuation; callers calculate and supply values themselves

A continued region ends with ContinuationAfter; the following region displays ContinuationBefore after any repeated headers

Both labels begin empty and use ContinuationStyle; each needs one line and its own reserved height, with no before label in the first region or after label in the last

Labels and borders are artifacts and do not alter table semantics; placeholders including {page} and {pages} go through the normal layout text resolver

Advanced table API and resource 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;

Initialise with TPdfLayoutTableOptions.Default before changing settings; AllowRowSpanContinuation starts as False, and MaxContinuationRegions permits 10,000 page or column regions by default, up to a configurable maximum of 100,000

Tables still allow 256 columns, 100,000 rows and 100,000 semantic elements; cell text altogether cannot exceed 8,000,000 UTF-16 code units

A mixed-text cell permits 1,024 added runs, 1,000,000 UTF-16 code units, 100,000 lines and 100,000 fragments; an overwide character, or word with long-word splitting disabled, is refused

A continued row group can contain 10,000 cells; region allowances and limited cut searches keep pagination finite, and images must fit the body area left after headers, labels and padding

The owned snapshot and cached plan include run styles, image sizes, alternate text, subtotal retention and continuation options; changing the caller's table later does not change 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