PDFium Delphi Component Docs

AddText method

Component: TPdf  ·  Unit: PDFium
Add text to the current PDF page at the specified position

Syntax

procedure AddText(const Text, Font: WString; FontSize: Single; X, Y: Double; Color: TColor = clBlack; Alpha: Byte = $FF; Angle: Double = 0.0);

FontSizeSingle. Font size in points (e.g. 12.0 for 12 pt text)
ColorTColor. Text fill colour. Default is clBlack
AlphaByte. Opacity of the text, where $00 is fully transparent and $FF is fully opaque. Default is $FF
AngleDouble. Rotation angle in degrees, measured anticlockwise from the positive X axis. Default is 0.0 (horizontal)

Description

AddText renders a Unicode text string onto the current PDF page using the specified font and size. The position (X, Y) is the baseline origin of the first character, measured in PDF user units from the bottom-left corner of the page (origin at bottom-left, Y increases upwards)

The font is identified by its PostScript or family name (e.g. 'Arial', 'Times New Roman'). The font must be available on the system or embedded in the document; if PDFium cannot locate the requested font it will substitute a default font

Use the Color and Alpha parameters to control the appearance of the text fill. Set Alpha to a value less than $FF to render semi-transparent text. The Angle parameter rotates the entire text string anticlockwise around the baseline origin

This method adds the text as a new page object. To modify the content of an existing text object after it has been added, use SetText

A system font is embedded once per document as a CID font keyed by code point: every Unicode character the font covers receives its own CID with an explicit CIDToGIDMap and a one-to-one ToUnicode entry, so characters sharing a glyph (space and U+00A0, hyphen and U+00AD, Omega and the Ohm sign) extract as exactly the characters that were written, from the live document and the saved file alike. Fonts without a Unicode cmap subtable fall back to the native glyph-keyed embedding

Native Free Pascal/LCL locates system-font files through fontconfig on Linux or CoreText on macOS, allowing at most 64 MiB per font file; if the requested family is missing, the platform may substitute another, and successful lookup does not guarantee every Unicode character is covered

Example

// Add a title string near the top of an A4 page
// A4 page height = 841.89 pt; place text 50 pt from the top
Pdf1.NewPage(595, 842);
Pdf1.AddText('Hello, PDFium Delphi Component!', 'Arial', 24, 72, 768);

// Red text at 45 degrees with 50% opacity
Pdf1.AddText('Rotated', 'Arial', 18, 200, 400, clRed, $80, 45);

See Also

AddImage, AddPicture, SetText, CreatePath