Dim caption As String = "Example: GetWordFontIsSmallcaps"
Dim oGdPictureOCR As GdPictureOCR = New GdPictureOCR
Dim oGdPicturePDF As GdPicturePDF = New GdPicturePDF
'Load the PDF document.
If oGdPicturePDF.LoadFromFile("input.pdf", False) = GdPictureStatus.OK Then
'Select the first page.
oGdPicturePDF.SelectPage(1)
'Render this page to a 200 DPI image.
Dim image As Integer = oGdPicturePDF.RenderPageToGdPictureImage(200, True)
If oGdPicturePDF.GetStat = GdPictureStatus.OK AndAlso
oGdPictureOCR.SetImage(image) = GdPictureStatus.OK Then
'Setting up the image is mandatory.
'Set up the OCR parameters.
oGdPictureOCR.ResourceFolder = "C:\Path\To\GdPicture.NET 14\Redist\OCR"
'Release default languages.
oGdPictureOCR.ResetSelectedDictionaries()
'Add required languages.
oGdPictureOCR.AddLanguage(OCRLanguage.Slovak)
oGdPictureOCR.AddLanguage(OCRLanguage.Czech)
'Set up the OCR mode.
oGdPictureOCR.OCRMode = OCRMode.FavorAccuracy
'Set up the OCR context and the character list.
oGdPictureOCR.Context = OCRContext.OCRContextSingleBlock
oGdPictureOCR.CharacterSet = ""
'Set up the area to be processed by the OCR.
oGdPictureOCR.SetROI(100, 100, 200, 200)
'Run the OCR process.
Dim resID As String = oGdPictureOCR.RunOCR()
If oGdPictureOCR.GetStat = GdPictureStatus.OK Then
Dim wordCount As Integer = oGdPictureOCR.GetWordCount(resID)
If oGdPictureOCR.GetStat() = GdPictureStatus.OK Then
Dim message As String = "The number of recognized words: " + wordCount.ToString()
'Analyze the results.
For i As Integer = 0 To wordCount - 1
message = message + vbCrLf + i.ToString() + ".word: " + oGdPictureOCR.GetWordValue(resID, i) +
message = " IsFromDict: " + oGdPictureOCR.GetWordIsFromDictionary(resID, i).ToString() +
message = " Language: " + oGdPictureOCR.GetWordRecognitionLanguage(resID, i) + vbCrLf +
message = " Font: " + oGdPictureOCR.GetWordFontFamilyName(resID, i) +
" size: " + oGdPictureOCR.GetWordFontSize(resID, i).ToString() +
" style: " + oGdPictureOCR.GetWordFontStyle(resID, i).ToString() + vbCrLf +
" monospaced" + oGdPictureOCR.GetWordFontIsMonospaced(resID, i).ToString() +
" serif" + oGdPictureOCR.GetWordFontIsSerif(resID, i).ToString() +
" smallcaps" + oGdPictureOCR.GetWordFontIsSmallcaps(resID, i).ToString()
Next
MessageBox.Show(message, caption)
Else
MessageBox.Show("The GetWordCount() method has failed with the status: " + oGdPictureOCR.GetStat().ToString(), caption)
End If
Else
MessageBox.Show("The error occurred when running the OCR. Status: " + oGdPictureOCR.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: " + oGdPicturePDF.GetStat().ToString() + "/" + oGdPictureOCR.GetStat().ToString(), caption)
End If
'Close the document.
oGdPicturePDF.CloseDocument()
Else
MessageBox.Show("The file can't be loaded. Status: " + oGdPicturePDF.GetStat().ToString(), caption)
End If
'Release resources.
oGdPictureOCR.ReleaseOCRResults()
oGdPictureOCR.Dispose()
oGdPicturePDF.Dispose()
string caption = "Example: GetWordFontIsSmallcaps";
GdPictureOCR oGdPictureOCR = new GdPictureOCR();
GdPicturePDF oGdPicturePDF = new GdPicturePDF();
//Load the PDF document.
if (oGdPicturePDF.LoadFromFile("input.pdf", false) == GdPictureStatus.OK)
{
//Select the first page.
oGdPicturePDF.SelectPage(1);
//Render this page to a 200 DPI image.
int image = oGdPicturePDF.RenderPageToGdPictureImage(200, true);
if ((oGdPicturePDF.GetStat() == GdPictureStatus.OK) &&
(oGdPictureOCR.SetImage(image) == GdPictureStatus.OK)) //Setting up the image is mandatory.
{
//Set up the OCR parameters.
oGdPictureOCR.ResourceFolder = "C:\\Path\\To\\GdPicture.NET 14\\Redist\\OCR";
//Release default languages.
oGdPictureOCR.ResetSelectedDictionaries();
//Add required languages.
oGdPictureOCR.AddLanguage(OCRLanguage.Slovak);
oGdPictureOCR.AddLanguage(OCRLanguage.Czech);
//Set up the OCR mode.
oGdPictureOCR.OCRMode = OCRMode.FavorAccuracy;
//Set up the OCR context and the character list.
oGdPictureOCR.Context = OCRContext.OCRContextSingleBlock;
oGdPictureOCR.CharacterSet = "";
//Set up the area to be processed by the OCR.
oGdPictureOCR.SetROI(100, 100, 200, 200);
//Run the OCR process.
string resID = oGdPictureOCR.RunOCR();
if (oGdPictureOCR.GetStat() == GdPictureStatus.OK)
{
int wordCount = oGdPictureOCR.GetWordCount(resID);
if (oGdPictureOCR.GetStat() == GdPictureStatus.OK)
{
string message = "The number of recognized words: " + wordCount.ToString();
//Analyze the results.
for (int i = 0; i < wordCount; i++)
{
message = message + "\n" + i.ToString() + ".word: " + oGdPictureOCR.GetWordValue(resID, i) +
message = " IsFromDict: " + oGdPictureOCR.GetWordIsFromDictionary(resID, i).ToString() +
message = " Language: " + oGdPictureOCR.GetWordRecognitionLanguage(resID, i) +
message = "\n Font: " + oGdPictureOCR.GetWordFontFamilyName(resID, i) +
" size: " + oGdPictureOCR.GetWordFontSize(resID, i).ToString() +
" style: " + oGdPictureOCR.GetWordFontStyle(resID, i).ToString() +
"\n: monospaced" + oGdPictureOCR.GetWordFontIsMonospaced(resID, i).ToString() +
" serif" + oGdPictureOCR.GetWordFontIsSerif(resID, i).ToString() +
" smallcaps" + oGdPictureOCR.GetWordFontIsSmallcaps(resID, i).ToString();
}
MessageBox.Show(message, caption);
}
else
MessageBox.Show("The GetWordCount() method has failed with the status: " + oGdPictureOCR.GetStat().ToString(), caption);
}
else
MessageBox.Show("The error occurred when running the OCR. Status: " + oGdPictureOCR.GetStat().ToString(), caption);
//Release the image.
GdPictureDocumentUtilities.DisposeImage(image);
}
else
MessageBox.Show("The error occurred when creating or setting up the image. Status: " + oGdPicturePDF.GetStat().ToString() + "/" + oGdPictureOCR.GetStat().ToString(), caption);
//Close the document.
oGdPicturePDF.CloseDocument();
}
else
MessageBox.Show("The file can't be loaded. Status: " + oGdPicturePDF.GetStat().ToString(), caption);
//Release resources.
oGdPictureOCR.ReleaseOCRResults();
oGdPictureOCR.Dispose();
oGdPicturePDF.Dispose();