THPDFHeadlessDocument.AppendPageText
procedure AppendPageText(PageIndex: Integer; const Text: UnicodeString;
const TrueTypeFont: SysUtils.TBytes; const Rectangle: THPDFRectangle;
const Options: THPDFHeadlessTextAppearanceOptions; Invisible: Boolean = False;
FitToRectangle: Boolean = False);
Append a genuine embedded Unicode Form XObject to an existing zero-based page without replacing original content; direct and indirect content arrays are normalised to stream references
Rectangle coordinates use PDF user space, and the appearance options control font, colour, spacing, alignment, shaping and counterclockwise quarter-turn rotation; 90 and 270 degrees exchange the logical text viewport width and height within the same physical rectangle
Page placement uses PDF decimal operands, preserving small positive and negative offsets
Negative and over-360 quarter-turn angles are normalised modulo 360, so -90 and 450 use the same logical viewport and transform as 270 and 90 respectively
OCR search layers use the compensating counterclockwise angle supplied by THPDFHeadlessOCRWord.AppearanceRotation to preserve text orientation when the page has clockwise display rotation
Invisible true inserts text rendering mode 3; FitToRectangle true fits single-line text using actual vertical font metrics and a logical horizontal transform that scales glyphs and their text origins together, including positions generated for nonzero CharacterSpacing or WordSpacing
The fitting transform follows the existing rectangle clip and precedes the text object, keeping the fitted text positions aligned with that clip while retaining vertical placement and the Form's quarter-turn rotation
Cloned page resource dictionaries preserve exact semantic names in Font, XObject and Properties, including spaces and literal #20 sequences, so original content keeps its resource references when text is appended, saved and reloaded
Only newly parsed serialised dictionary clones normalise their escaped keys once; existing normalised resource graphs are not decoded again, and a space-containing name remains distinct from a literal #20 name
Resources are cloned before mutation, generated objects are preflighted against document limits, cancellation and preflight failure preserve the original page, and encrypted saves use the original AES security policy
User-password page editing requires content modification permission; signed or certified documents require an editing policy outside this method and are rejected
Historical verification covered native Linux FPC 3.2.2/3.3.1, Windows FPC and Delphi Win32/Win64, C++Builder headers, strict independent extraction and pixel-identical invisible search layers; those results retain their original compiler and source identities
Current acceptance requires FPC 3.3.1 or later on every platform and records the actual tested build; compatibility with earlier FPC versions is deferred until a real customer requirement justifies restoring it