PDFium Delphi Component Docs

FindFirst Yöntem

Component: TPdf  ·  Unit: PDFium
Belirtilen metnin aramasını başlatır. StartIndex 0 tabanlıdır, -1 sayfanın sonunu ifade eder. DirectionUp parametresi bu arama işleminin yönünü belirler

Syntax

function FindFirst(const Text: WString; Options: TSearchOptions = []; StartIndex: Integer = 0; DirectionUp: Boolean = True): Integer;

TextWString. Geçerli sayfada aranacak Unicode metin stringi
OptionsTSearchOptions. A set of TSearchOption flags that control matching behavior. Supported flags are soMatchCase (case-sensitive match) and soMatchWholeWord (whole-word match only). Pass [] for a case-insensitive, substring search.
StartIndexInteger. Aramanın başlayacağı sıfır tabanlı karakter indeksi. Sayfanın son karakterinden başlamak için -1 geçirin (DirectionUp False iken kullanışlıdır). Varsayılan 0
DirectionUpBoolean. Determines the initial search direction. True (default) searches from StartIndex toward the end of the page; False searches toward the beginning. Subsequent calls to FindNext always move forward; FindPrevious always moves backward.

Return Value

The 0-based character index of the first match, or -1 eşleşme bulunmazsa. Dahili arama tanıtıcısı tutulur, böylece sonraki şu çağrılar FindNext or FindPrevious can continue the search without reinitialisation.

Description

FindFirst initiates a full-text search on the currently loaded PDF page. It accepts a Unicode search string together with optional matching flags, a starting character position, and a direction hint. On success it returns the 0-based character index of the first match and stores an internal search handle that is reused by subsequent FindNext and FindPrevious calls. Returns -1 when the text is not found.

StartIndex parametresi, aramayı her zaman sayfanın tepesinden başlatmak yerine herhangi bir karakter konumundan başlatmanızı sağlar. Çok ilk karakterden başlamak için 0 (varsayılan) geçirin veya DirectionUp = False ile ters yönlü arama yaparken kullanışlı olan son karaktere çıpalamak için -1 geçirin

Eşleştirme davranışını inceltmek için Options parametresini kullanın. soMatchCase büyük/küçük harf duyarlı karşılaştırmayı açar; soMatchWholeWord eşleşmeleri yalnızca bütün kelimelerle sınırlar. İki bayrak birleştirilebilir. Boş bir [] kümesi geçirmek, büyük/küçük harf duyarsız alt string araması yapar

Eşleşme bulunduktan sonra, sayfadaki eşleşen metnin sınır dikdörtgenlerini almak için döndürülen indeks ve bilinen eşleşme uzunluğuyla RectangleCount'u çağırın — bir görüntüleyicide arama sonuçlarını vurgulamak için kullanışlıdır

Example

var
  Idx, MatchLen, R, I: Integer;
  Rect: TPdfRectangle;
begin
  Pdf1.PageIndex := 0;
  MatchLen := Length('invoice');
  Idx := Pdf1.FindFirst('invoice', [], 0, True);
  while Idx >= 0 do
  begin
    // Retrieve bounding rectangles for the matched text
    R := Pdf1.RectangleCount(Idx, MatchLen);
    for I := 0 to R - 1 do
    begin
      Rect := Pdf1.Rectangle[I];
      Memo1.Lines.Add(Format('Match at char %d, rect [%.1f,%.1f,%.1f,%.1f]',
        [Idx, Rect.Left, Rect.Top, Rect.Right, Rect.Bottom]));
    end;
    Idx := Pdf1.FindNext;
  end;
end;

See Also

FindNext, FindPrevious, Find, CharacterIndexAtPos, CharacterCount, RectangleCount, Text