property ObjectBounds[Index: Integer]: TPdfRectangle; // read only
page の PDF content stream は page objects の列です。ここには text run、vector path、raster image、shading pattern、埋め込み form XObject (PDF 32000-1
§ 8.2) が含まれます。ObjectBounds は、PDFium が CTM stack と object 自身の cm matrix を平坦化した後の、現在 page にある Index 番の object の bounding box を返します。余計な計算なしで hit testing、mask building、thumbnail crop にそのまま使えます
rectangle は標準的な PDF 座標規約を使います。原点は page 左下、単位は 1/72 inch、Y は上向きです。したがって、整形式の文書では Bottom < Top になります。PDFium の FPDFPageObj_GetBounds を包んでおり、呼び出し自体は O(1) ですが、path については内部で全 contour vertex を走査します。1 object あたり何度も読むなら結果を cache するのが賢明です
有効範囲は PageNumber で選択されている page の 0 .. ObjectCount - 1 です。範囲外 index へ access すると zero rectangle が返ります。追加の per-type property を読む前に object の種類で分岐するなら、この property を ObjectType と組み合わせてください
| Index | ゼロベースの page-object index で、0 ≤ Index < ObjectCount です |
// Highlight every image object on the current page.
var I: Integer;
var R: TPdfRectangle;
begin
for I := 0 to Pdf1.ObjectCount - 1 do
if Pdf1.ObjectType[I] = otImage then
begin
R := Pdf1.ObjectBounds[I];
Memo1.Lines.Add(Format('image %d: %.1f,%.1f - %.1f,%.1f (%.1fx%.1f pt)',
[I, R.Left, R.Bottom, R.Right, R.Top,
R.Right - R.Left, R.Top - R.Bottom]));
end;
end;