Dim caption As String = "Example: GetCharacterWordIndex"
Dim gdpictureOCR As GdPictureOCR = New GdPictureOCR()
Dim gdpicturePDF As GdPicturePDF = New GdPicturePDF()
'Load the PDF document.
If gdpicturePDF.LoadFromFile("input.pdf", False) = GdPictureStatus.OK Then
'Select the first page.
gdpicturePDF.SelectPage(1)
'Render this page to a 200 DPI image.
Dim image As Integer = gdpicturePDF.RenderPageToGdPictureImage(200, True)
'Setting up the image is mandatory.
If (gdpicturePDF.GetStat() = GdPictureStatus.OK) AndAlso
(gdpictureOCR.SetImage(image) = GdPictureStatus.OK) Then
'Set up the OCR parameters.
gdpictureOCR.ResourcesFolder = "C:\Path\To\GdPicture.NET 14\Redist\OCR"
gdpictureOCR.AddLanguage(OCRLanguage.English)
gdpictureOCR.OCRMode = OCRMode.FavorAccuracy
'Set up the OCR context and the character list.
gdpictureOCR.Context = OCRContext.OCRContextDocument
gdpictureOCR.CharacterSet = "@"
'Run the OCR process to recognize the character.
Dim resID As String = gdpictureOCR.RunOCR()
If gdpictureOCR.GetStat() = GdPictureStatus.OK Then
Dim wordCount As Integer = gdpictureOCR.GetWordCount(resID)
If gdpictureOCR.GetStat() = GdPictureStatus.OK Then
Dim message As String = "The number of all recognized words: " + wordCount.ToString() + vbCrLf
Dim charCount As Integer = gdpictureOCR.GetCharacterCount(resID)
If gdpictureOCR.GetStat() = GdPictureStatus.OK Then
message = message + "The number of all recognized characters: " + charCount.ToString() + vbCrLf
For i As Integer = 0 To charCount - 1
message = message + "The character nr." + i.ToString() + " is included in the word nr." +
gdpictureOCR.GetCharacterWordIndex(resID, i).ToString() + "." + vbCrLf
Next
MessageBox.Show(message, caption)
'Continue with analyzing the result ...
Else
MessageBox.Show("The GetCharacterCount() method has failed with the status: " + gdpictureOCR.GetStat().ToString(), caption)
End If
Else
MessageBox.Show("The GetWordCount() method has failed with the status: " + gdpictureOCR.GetStat().ToString(), caption)
End If
Else
MessageBox.Show("The error occurred when running the OCR. Status: " + gdpictureOCR.GetStat().ToString(), caption)
End If
'Release the image.
GdPictureDocumentUtilities.DisposeImage(image)
Else
MessageBox.Show("The error occurred when creating or setting up the image. Status: " + gdpicturePDF.GetStat().ToString() + "/" + gdpictureOCR.GetStat().ToString(), caption)
End If
'Close the document.
gdpicturePDF.CloseDocument()
Else
MessageBox.Show("The file can't be loaded. Status: " + gdpicturePDF.GetStat().ToString(), caption)
End If
'Release resources.
gdpictureOCR.ReleaseOCRResults()
gdpictureOCR.Dispose()
gdpicturePDF.Dispose()
string caption = "Example: GetCharacterWordIndex";
GdPictureOCR gdpictureOCR = new GdPictureOCR();
GdPicturePDF gdpicturePDF = new GdPicturePDF();
//Load the PDF document.
if (gdpicturePDF.LoadFromFile("input.pdf", false) == GdPictureStatus.OK)
{
//Select the first page.
gdpicturePDF.SelectPage(1);
//Render this page to a 200 DPI image.
int image = gdpicturePDF.RenderPageToGdPictureImage(200, true);
if ((gdpicturePDF.GetStat() == GdPictureStatus.OK) &&
(gdpictureOCR.SetImage(image) == GdPictureStatus.OK)) //Setting up the image is mandatory.
{
//Set up the OCR parameters.
gdpictureOCR.ResourcesFolder = "C:\\Path\\To\\GdPicture.NET 14\\Redist\\OCR";
gdpictureOCR.AddLanguage(OCRLanguage.English);
gdpictureOCR.OCRMode = OCRMode.FavorAccuracy;
//Set up the OCR context and the character list.
gdpictureOCR.Context = OCRContext.OCRContextDocument;
gdpictureOCR.CharacterSet = "@";
//Run the OCR process to recognize the character.
string resID = gdpictureOCR.RunOCR();
if (gdpictureOCR.GetStat() == GdPictureStatus.OK)
{
int wordCount = gdpictureOCR.GetWordCount(resID);
if (gdpictureOCR.GetStat() == GdPictureStatus.OK)
{
string message = "The number of all recognized words: " + wordCount.ToString() + "\n";
int charCount = gdpictureOCR.GetCharacterCount(resID);
if (gdpictureOCR.GetStat() == GdPictureStatus.OK)
{
message = message + "The number of all recognized characters: " + charCount.ToString() + "\n";
for (int i = 0; i < charCount; i++)
{
message = message + "The character nr." + i.ToString() + " is included in the word nr." +
gdpictureOCR.GetCharacterWordIndex(resID, i).ToString() + ".\n";
}
MessageBox.Show(message, caption);
//Continue with analyzing the result ...
}
else
MessageBox.Show("The GetCharacterCount() method has failed with the status: " + gdpictureOCR.GetStat().ToString(), caption);
}
else
MessageBox.Show("The GetWordCount() method has failed with the status: " + gdpictureOCR.GetStat().ToString(), caption);
}
else
MessageBox.Show("The error occurred when running the OCR. Status: " + gdpictureOCR.GetStat().ToString(), caption);
//Release the image.
GdPictureDocumentUtilities.DisposeImage(image);
}
else
MessageBox.Show("The error occurred when creating or setting up the image. Status: " + gdpicturePDF.GetStat().ToString() + "/" + gdpictureOCR.GetStat().ToString(), caption);
//Close the document.
gdpicturePDF.CloseDocument();
}
else
MessageBox.Show("The file can't be loaded. Status: " + gdpicturePDF.GetStat().ToString(), caption);
//Release resources.
gdpictureOCR.ReleaseOCRResults();
gdpictureOCR.Dispose();
gdpicturePDF.Dispose();