TPdfMeasureHelper = class helper for TPdf
procedure MeasureText(const Text, Font: WString; FontSize: Single; out Width, Height: Double);
function MeasureTextWidth(const Text, Font: WString; FontSize: Single): Double;
function WrapText(const Text, Font: WString; FontSize: Single; MaxWidth: Double): TArray<WString>;
function WrapText(const Text, Font: WString; FontSize: Single; MaxWidth: Double; BreakLongWords: Boolean): TArray<WString>;
end;
| Member | Description |
|---|---|
TPdf.MeasureText | Returns text width and height in PDF user units for the selected font and size |
TPdf.MeasureTextWidth | Returns only the text width in PDF user units |
TPdf.WrapText | Preserves explicit line breaks, wraps tokens to MaxWidth, and can split oversized tokens at Unicode scalar boundaries |
FPdfMeasure adds a class helper to TPdf so text can be measured in PDF user units before drawing
TPdfMeasureHelper is that helper: it measures through a temporary native text object that is created, bounded and destroyed without anything being added to a page, and it yields a zero extent when no document is loaded or the text object cannot be built
Use MeasureText and MeasureTextWidth for layout calculations, and WrapText to split text into lines that fit a chosen width
The original WrapText overload keeps an oversized token intact for compatibility; pass BreakLongWords=True to split CJK or other text without spaces while preserving UTF-16 surrogate pairs
var
Width, Height: Double;
Lines: TArray<WString>;
begin
Pdf.MeasureText('Invoice total', 'Arial', 12, Width, Height);
Lines := Pdf.WrapText(LongText, 'Arial', 10, 240, True);
end;