The SearchText and DocSearchText methods are used to search for a specific text from WinAnsi encoded streams only.
It is recommended to use SearchTextEx rather than SearchText for ActiveX version.
System.Boolean SearchText(System.Int16 Start, System.String Text, [out] System.Int32 Page, [out] System.Double xPos, [out] System.Double yPos)
int DocSearchTextW(EXTDOCHANDLE edhDocument, short Start, LPCWSTR Text, long* Page, double* xPos, double* yPos)
Start
(-1): Start from the beginning of the document, otherwise start from the previous Search position.
Text
Text to search for.
Page
This is a return value that contains the page number(one based index)where text was found.
xPos
This is a return value of the x coordinate where the text was found.
yPos
This is a return value of the y coordinate where the text was found.
edhDocument
Handle Returned by DocOpen.
The return value is True if the SearchText method succeed. Otherwise, False If the SearchText method fails.
The return value is zero if the DocSearchText method succeed. If the DocSearchText method fails, a negative value will returned.
SearchText method for the ActiveX is less accurate in returning the text position but much faster than SearchTextEx method.
It only also works with WinAnsi encoded streams, but not with other encodings. Check SearchTextEx method for Unicode text for ActiveX version.
Member of CDIntfEx.Document.
Public Sub Sample()
' Constants for Activation codes
Const strLicenseTo As String = "Amyuni PDF Converter Evaluation"
Const strActivationCode As String = "07EFCDAB0100010025AFF1801CB9441306C5739F7D452154D8833B9CECBA2ADE79E3762A69FFC354528A5F4A5811BE3204A0A439F5BA"
' Declare a new cdintfex document if it does not exist in the form.
Dim pdfDoc As New CDIntfEx.Document
' The SetLicenseKey method should be called after creating an object of type
' CDIntfEx.Document to activate the advanced methods that require the object
' activation code to work properly
pdfDoc.SetLicenseKey(strLicenseTo, strActivationCode)
' Open the document
pdfDoc.Open("c:\temp\test.pdf")
' Search Text
Dim xPos As Double
Dim yPos As Double
Dim page As Long
Dim strFind As String = "Test"
If pdfDoc.SearchText(0, strFind, page, xPos, yPos) Then
MsgBox("SearchText: " & strFind & " String Found!" & Environment.NewLine &
"Page=" & page & ", Position Horizontal=" & xPos & ", Position Vertical=" & yPos)
Else
MsgBox("SearchText: " & strFind & " String Not Found!")
End If
End Sub
public void Sample()
{
// Constants for Activation codes
const string strLicenseTo = "Amyuni PDF Converter Evaluation";
const string strActivationCode = "07EFCDAB0100010025AFF1801CB9441306C5739F7D452154D8833B9CECBA2ADE79E3762A69FFC354528A5F4A5811BE3204A0A439F5BA";
// Declare a new cdintfex document if it does not exist in the form.
CDIntfEx.Document pdfDoc = new CDIntfEx.Document();
// The SetLicenseKey method should be called after creating an object of type
// CDIntfEx.Document to activate the advanced methods that require the object
// activation code to work properly
pdfDoc.SetLicenseKey(strLicenseTo, strActivationCode);
// Open the document
pdfDoc.Open(@"c:\temp\\test.pdf");
// Search Text
double xPos = 0;
double yPos = 0;
int page = 0;
string strFind = "Test";
if (pdfDoc.SearchText(0, strFind, ref page, ref xPos, ref yPos))
{
MessageBox.Show("SearchText: " + strFind + " String Found!" + Environment.NewLine +
"Page=" + page + ", Position Horizontal=" + xPos + ", Position Vertical=" + yPos);
}
else
{
MessageBox.Show("SearchText: " + strFind + " String Not Found!");
}
}
// PDF Converter Cpp.cpp : Defines the entry point for the console application.
//
#include <Windows.h>
#include "CdIntf.h"
#include <iostream>
#pragma comment (lib, "CDIntf.lib")
using namespace std;
int main()
{
// Constants for Activation codes
#define strLicenseTo "Amyuni Tech. Evaluation"
#define strActivationCode "07EFCDAB01000100DF6EFC8664508CC905BADA9A6C56066D8219C78B8804C5D09ECA85769789782B3945B0ECA66CB3612C5D7772F0B9"
// Declare a new cdintfex document if it does not exist in the form.
EXTDOCHANDLE pdfDoc;
// The SetLicenseKey method should be called after creating an object of type
// CDIntfEx.Document to activate the advanced methods that require the object
// activation code to work properly
SetLicenseKeyA(strLicenseTo, strActivationCode);
// Open the document
LPBYTE passWord = nullptr;
DocOpenA(&pdfDoc, "C:\temp\\test.pdf", passWord);
// Search Text
double xPos = 0;
double yPos = 0;
long page = 0;
LPCWSTR strFind = (LPCWSTR)"Test";
if (DocSearchTextW(pdfDoc, 0, strFind, &page, &xPos, &yPos)==0)
{
cout << "SearchText: " << strFind << " String Found!" << endl <<
"Page=" << page << ", Position Horizontal=" << xPos << ", Position Vertical=" << yPos << endl;
}
else
{
cout << "SearchText: " << strFind << " String Not Found!" << endl;
}
// Destroy pdfDoc object
DocClose(pdfDoc);
pdfDoc = nullptr;
return 0;
}