procedure SetTextPositions(ObjectIndex: Integer; const Positions: TPdfSingleArray);
| ObjectIndex | Integer. Zero-based index of the text object whose character positions are to be set (0 to ObjectCount - 1). |
| Positions | TPdfSingleArray. Array of per-character offsets in points, relative to the text object origin. Positions[0] sets the position of the second character, Positions[1] the third, and so on. The first character is always at position 0. |
SetTextPositions overrides the default character spacing of a text object by supplying an explicit horizontal offset for each character. This enables fine-grained kerning control, justified text layout, or reproduction of the exact character placement found in an existing PDF.
The Positions array contains one entry per inter-character gap, starting from the gap between the first and second characters. Specifically, Positions[0] is the position of the second character, Positions[1] is the position of the third character, and so on — all measured in points from the text object's origin along the text baseline. The first character is always placed at offset 0. The array length should be one less than the number of characters in the text object; surplus entries are ignored and missing entries leave the corresponding characters at their default positions.
This method is typically used together with SetText when reconstructing or editing text objects whose original character spacing must be preserved exactly.
// Add text, then apply custom per-character positions
Pdf1.NewPage(595, 842);
Pdf1.AddText('HELLO', 'Arial', 24, 72, 700);
var
Idx: Integer;
Pos: TPdfSingleArray;
begin
Idx := Pdf1.ObjectCount - 1;
// 'H' at 0 (implicit), 'E' at 20, 'L' at 38, 'L' at 56, 'O' at 74
SetLength(Pos, 4);
Pos[0] := 20; Pos[1] := 38; Pos[2] := 56; Pos[3] := 74;
Pdf1.SetTextPositions(Idx, Pos);
end;