function RectangleCount(StartIndex: Integer = 0; Count: Integer = MaxInt): Integer;
| StartIndex | Integer. The 0-based index of the first character in the segment to measure. Defaults to 0. |
| Count | Integer. The number of characters to include in the measurement, starting from StartIndex. Defaults to MaxInt, which covers all remaining characters on the page. |
Rectangle[0] through Rectangle[RectangleCount - 1] indexed property.RectangleCount calculates the set of bounding rectangles that together cover a contiguous run of characters on the current page. Characters on the same line that share the same font settings are automatically merged into a single rectangle, reducing the result to the minimum number of non-overlapping boxes needed to highlight the text.
The StartIndex and Count parameters define the character segment to measure. A typical use is to pass the match index returned by FindFirst or FindNext as StartIndex, and the length of the search string as Count, in order to obtain highlight rectangles for a search result.
The returned rectangles are stored in an internal buffer and remain valid until the next call to RectangleCount. Retrieve each rectangle by reading the Rectangle[Index] property for Index in the range 0 to RectangleCount - 1. All coordinates are in PDF user-space units (points, origin at lower-left).
For a plain count of all characters on the page use CharacterCount; to find where a specific character sits on the page use CharacterIndexAtPos.
var
MatchIdx, RCount, I: Integer;
Rect: TPdfRectangle;
begin
Pdf1.PageIndex := 0;
MatchIdx := Pdf1.FindFirst('PDFium');
if MatchIdx >= 0 then
begin
RCount := Pdf1.RectangleCount(MatchIdx, Length('PDFium'));
for I := 0 to RCount - 1 do
begin
Rect := Pdf1.Rectangle[I];
// Draw a highlight box using Rect.Left/Top/Right/Bottom
Memo1.Lines.Add(Format('Rect %d: (%.1f, %.1f, %.1f, %.1f)',
[I, Rect.Left, Rect.Bottom, Rect.Right, Rect.Top]));
end;
end;
end;