SearchText(String,Int32,Boolean,Boolean,Single,Single,Single,Single) Method
Searches for an occurrence of a given text expression within the current page of the loaded PDF document according to the parameters you have specified. This method returns the bounding box (rectangle) surrounding the searched expression defined by its top left coordinates and by its width and height in inches, if the expression has been found.
This method uses the InvariantCulture comparison when searching. It means, that characters are comparing using culture-sensitive sort rules and the invariant culture, in other words this method respects accents when searching.
public bool SearchText(
string ,
int ,
bool ,
bool ,
ref float ,
ref float ,
ref float ,
ref float
)
public function SearchText(
: String;
: Integer;
: Boolean;
: Boolean;
var : Single;
var : Single;
var : Single;
var : Single
): Boolean;
public function SearchText(
: String,
: int,
: boolean,
: boolean,
: float,
: float,
: float,
: float
) : boolean;
public: bool SearchText(
string* ,
int ,
bool ,
bool ,
ref float ,
ref float ,
ref float ,
ref float
)
public:
bool SearchText(
String^ ,
int ,
bool ,
bool ,
float% ,
float% ,
float% ,
float%
)
'Declaration
Public Overloads Function SearchText( _
ByVal As String, _
ByVal As Integer, _
ByVal As Boolean, _
ByVal As Boolean, _
ByRef As Single, _
ByRef As Single, _
ByRef As Single, _
ByRef As Single _
) As Boolean
Parameters
- Text
- The text expression to search for.
- Occurrence
- The occurrence (rank) of the searched expression on the current page. Set the occurrence to 1 if you are searching for the first occurrence, set it to 2 for the second etc.
Rank equal to 0 is not accepted, it will always be converted to 1. Please note that the occurrence (rank) is always related to the current page.
- CaseSensitive
- Set this parameter to true if you want to apply case-sensitive search, otherwise set it to false.
- WholeWords
- Set this parameter to true if you want to search for the whole words only, otherwise set it to false.
- Left
- Output parameter. If the searched expression has been found, this is the horizontal (X) coordinate of the top left point of its surrounding bounding box, in inches.
- Top
- Output parameter. If the searched expression has been found, this is the vertical (Y) coordinate of the top left point of its surrounding bounding box, in inches.
- Width
- Output parameter. If the searched expression has been found, this is the width of the bounding box surrounding the expression, in inches.
- Height
- Output parameter. If the searched expression has been found, this is the height of the bounding box surrounding the expression, in inches.
Return Value
true if the given text expression has been found on the current page according to the specified parameters, otherwise false. The
GdPicturePDF.GetStat method can be subsequently used to determine if this method has been successful.
How to search for all occurrences of a specified text expression across the whole PDF document.
Dim caption As String = "Example: SearchText"
Dim gdpicturePDF As New GdPicturePDF()
Dim status As GdPictureStatus = gdpicturePDF.LoadFromFile("test.pdf", False)
If status = GdPictureStatus.OK Then
Dim text_file As New System.IO.StreamWriter("search_text.txt")
Dim pageCount As Integer = gdpicturePDF.GetPageCount()
status = gdpicturePDF.GetStat()
If status = GdPictureStatus.OK Then
Dim textToFind As String = "text"
Dim message As String = Nothing
Dim occurrence As Integer = 1
Dim found As Boolean = False
Dim posLeft As Single = 0, posTop As Single = 0, posWidth As Single = 0, posHeight As Single = 0
For i As Integer = 1 To pageCount
status = gdpicturePDF.SelectPage(i)
If status = GdPictureStatus.OK Then
message = "Page: " + i.ToString() + " Status: " + status.ToString()
text_file.WriteLine(message)
'The occurrence of the searched text is related to the current page.
occurrence = 1
Do
found = gdpicturePDF.SearchText(textToFind, occurrence, False, False, posLeft, posTop, posWidth, posHeight)
status = gdpicturePDF.GetStat()
If status = GdPictureStatus.OK AndAlso found Then
message = "Occurrence: " + occurrence.ToString() + " Position: (" + posLeft.ToString() + ";" + posTop.ToString() + ";" + posWidth.ToString() + ";" + posHeight.ToString() + ")"
text_file.WriteLine(message)
End If
occurrence += 1
Loop While found = True
Else
MessageBox.Show("The SelectPage() method has failed with the status: " + status.ToString(), caption)
End If
Next
Else
MessageBox.Show("The GetPageCount() method has failed with the status: " + status.ToString(), caption)
End If
text_file.Close()
Else
MessageBox.Show("The file can't be loaded.", caption)
End If
MessageBox.Show("Searching finished.", caption)
gdpicturePDF.Dispose()
string caption = "Example: SearchText";
GdPicturePDF gdpicturePDF = new GdPicturePDF();
GdPictureStatus status = gdpicturePDF.LoadFromFile("test.pdf", false);
if (status == GdPictureStatus.OK)
{
System.IO.StreamWriter text_file = new System.IO.StreamWriter("search_text.txt");
int pageCount = gdpicturePDF.GetPageCount();
status = gdpicturePDF.GetStat();
if (status == GdPictureStatus.OK)
{
string textToFind = "text";
string message = null;
int occurrence = 1;
bool found = false;
float posLeft = 0, posTop = 0, posWidth = 0, posHeight = 0;
for (int i = 1; i <= pageCount; i++)
{
status = gdpicturePDF.SelectPage(i);
if (status == GdPictureStatus.OK)
{
message = "Page: " + i.ToString() + " Status: " + status.ToString();
text_file.WriteLine(message);
//The occurrence of the searched text is related to the current page.
occurrence = 1;
do
{
found = gdpicturePDF.SearchText(textToFind, occurrence, false, false, ref posLeft, ref posTop, ref posWidth, ref posHeight);
status = gdpicturePDF.GetStat();
if (status == GdPictureStatus.OK && found)
{
message = "Occurrence: " + occurrence.ToString() + " Position: (" + posLeft.ToString() + ";" + posTop.ToString() + ";" + posWidth.ToString() + ";" + posHeight.ToString() + ")";
text_file.WriteLine(message);
}
occurrence++;
} while (found == true);
}
else
{
MessageBox.Show("The SelectPage() method has failed with the status: " + status.ToString(), caption);
}
}
}
else
{
MessageBox.Show("The GetPageCount() method has failed with the status: " + status.ToString(), caption);
}
text_file.Close();
}
else
{
MessageBox.Show("The file can't be loaded.", caption);
}
MessageBox.Show("Searching finished.", caption);
gdpicturePDF.Dispose();