PDFium Component Docs

TextInRectangle 메서드

이 API 항목은 식별자, 시그니처, 코드 블록, PDF 용어를 원래 형태로 유지합니다.
컴포넌트: TPdf  ·  유닛: PDFium
Extract text within a rectangular boundary on the page.

구문

function TextInRectangle(Left, Top, Right, Bottom: Double): WString;

 

function TextInRectangle(Rectangle: TPdfRectangle): WString;

RectangleTPdfRectangle. A record specifying the bounding rectangle in PDF user-space coordinates (origin at lower-left, Y increases upward).

Return Value

A WString (Unicode string) containing all characters whose bounding boxes intersect the specified rectangle. Returns an empty string if no text is found within the region.

설명

TextInRectangle는 현재 페이지의 지정한 사각형 영역 안에 들어오는 Unicode 텍스트를 추출합니다. 전체 페이지를 처리하지 않고 헤더, 푸터, 표 셀 또는 필드 레이블 같은 특정 영역의 텍스트를 읽을 때 유용합니다

두 가지 오버로드가 제공됩니다. 네 매개변수 형식은 개별 Left, Top, Right, Bottom 값을 받습니다. 단일 매개변수 형식은 TPdfRectangle record를 받으며, 영역이 이미 rectangle structure로 계산되어 있을 때 편리합니다

좌표는 PDF user space를 사용하며 원점은 페이지의 왼쪽 아래 모서리이고 Y는 위로 증가합니다. 따라서 일반적인 방향의 rectangle에서는 BottomTop보다 작은 값입니다. 문자들은 bounding box가 지정한 영역과 겹치면 결과에 포함됩니다

Text와 마찬가지로 이 메서드는 페이지의 logical text layer에서 읽으며 loaded PDF page에서만 동작합니다

예제

// Extract text from the top header area of an A4 page
// A4: 595 x 842 pt; header = top 60 pt band
Pdf1.LoadFromFile('C:\Docs\report.pdf');
Pdf1.PageIndex := 0;
var HeaderText: WString;
begin
  HeaderText := Pdf1.TextInRectangle(0, 782, 595, 842);
  ShowMessage(HeaderText);
end;

// Using TPdfRectangle overload
var
  Rect: TPdfRectangle;
  CellText: WString;
begin
  Rect.Left := 72; Rect.Bottom := 600;
  Rect.Right := 250; Rect.Top := 640;
  CellText := Pdf1.TextInRectangle(Rect);
end;

참고 항목

Text, CharacterCount, FindFirst