PDFium Delphi Component Docs

метод Text

Компонент: TPdf  ·  Модул: PDFium
Извлича текстов низ от страницата. Параметрите StartIndex и Count определят кои знаци да бъдат извлечени. Параметърът StartIndex е 0-базиран

Синтаксис

function Text(StartIndex: Integer = 0; Count: Integer = MaxInt): WString;

StartIndexInteger. Zero-based index of the first character to extract. Default is 0 (start of page text).
CountInteger. Maximum number of characters to extract. Default is MaxInt, which extracts all remaining characters from StartIndex to the end of the page.

Върната стойност

WString (Unicode низ), съдържащ извлечените знаци. Връща празен низ, ако StartIndex е след края на текста на страницата или ако страницата не съдържа извлекаем текст

Описание

Text extracts the Unicode text content from the current page as a plain string. It reads from the page's internal text layer — the same layer used by PDF viewers for text selection and search — so the result reflects the logical reading order as determined by PDFium, which may differ from the visual order for complex layouts.

The optional StartIndex and Count parameters allow extracting a substring of the full page text. StartIndex is zero-based; omitting both parameters returns the entire page text. Use CharacterCount to determine the total number of extractable characters on the page before using index-based access.

This method extracts text from a loaded PDF page. It does not interact with text objects added via AddText until the document has been saved and reloaded. To extract text within a specific rectangular region, use TextInRectangle instead.

Пример

// Extract all text from the first page
Pdf1.LoadFromFile('C:\Docs\report.pdf');
Pdf1.PageIndex := 0;
ShowMessage(Pdf1.Text);

// Extract characters 10..29 (20 characters)
var S: WString;
begin
  S := Pdf1.Text(10, 20);
end;

Виж също

TextInRectangle, CharacterCount, FindFirst, Character