The class Pdf (gb.poppler) is static and provides 4 numerical constants in relation to the search in a PDF document with the method hPdfDocument.Find(argSuchtext, [ argSuchOption ]):
Constant | Value | Description |
---|---|---|
CaseSensitive | 1 | Case case sensitive |
Backwards | 2 | Backward search |
WholeWordsOnly | 4 | Search for whole words only |
IgnoreDiacritics | 8 | Ignore diacritical characters |
Table 23.12.4.1 : Constants of the Pdf class
The following source code can be used to search for a specific text in a PDF file. The coordinates of the text-enclosing rectangle are displayed in the IDE console:
Public Sub SearchText(sSearchText As String, Optional iSearchOption As Integer) Dim i As Integer Dim aRectF As New RectF[] If IsNull(iSearchOption) Then iSearchOption = 0 For i = 0 To $hPdfDocument.Max aRectF = $hPdfDocument[i].FindText(sSearchText, iSearchOption) If aRectF.Count > 0 Then For Each hRectF As RectF In aRectF Print "x: "; Round(hRectF.X, -1); " y: "; Round(hRectF.Y, -1); Print " | w: "; Round(hRectF.W, -1); " h: "; Round(hRectF.H, -1) Next Endif Next End
This text is located in the file simpletext.pdf:
Er programmiert in der Programmiersprache Gambas. Fazit: Gambas ist toll!
Calling the procedure with the search text “Gambas” and two search options:
SearchText("Gambas", Pdf.CaseSensitive Or Pdf.WholeWordsOnly)
results in this display in the console:
Rechteck-Koordinaten: ---------------------------------------- x: 66,6 y: 736,3 | w: 52,9 h: 15,6