PDFiumVCL 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; Colour: TColor = clBlack; Alpha: Byte = $FF; Angle: Double = 0.0);

FontSizeSingle. Font size in points (e.g. 12.0 for 12 pt text).
ColourTColor. 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 counterclockwise 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 lower-left corner of the page (origin at lower-left, Y increases upward).

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 counterclockwise 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.

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, PDFiumVCL!', '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