GetTextLineValue Method (GdPictureOCR)
In This Topic
Gets the value of the specified line, that is a part of a specified OCR result.
Syntax
'Declaration
Public Function GetTextLineValue( _
ByVal As String, _
ByVal As Integer _
) As String
public string GetTextLineValue(
string ,
int
)
public function GetTextLineValue(
: String;
: Integer
): String;
public function GetTextLineValue(
: String,
: int
) : String;
public: string* GetTextLineValue(
string* ,
int
)
public:
String^ GetTextLineValue(
String^ ,
int
)
Parameters
- OCRResultID
- The unique result identifier of the executed OCR process obtained by the GdPictureOCR.RunOCR method.
- TextLineIdx
- The 0-based index of the line within the specified OCR result. It must be a value between 0 and GdPictureOCR.GetTextLineCount(OCRResultID) - 1.
Return Value
The value of the specified line. Please always use the
GdPictureOCR.GetStat method to determine if this method has been successful.
Example
How to find out the recognized lines.
Dim caption As String = "Example: GetTextLineValue"
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
'Set the new origin for better coordinates handling.
gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft)
gdpicturePDF.SetLineColor(Color.Olive)
gdpicturePDF.SetLineWidth(2)
'Select the first page.
gdpicturePDF.SelectPage(1)
'Render this page to a 200 DPI image.
Dim image As Integer = gdpicturePDF.RenderPageToGdPictureImage(200, True)
If gdpicturePDF.GetStat = GdPictureStatus.OK AndAlso
gdpictureOCR.SetImage(image) = GdPictureStatus.OK Then
'Setting up the image is mandatory.
Dim message As String = Nothing
'Set up the OCR parameters.
gdpictureOCR.ResourcesFolder = "C:\Path\To\GdPicture.NET 14\Redist\OCR"
gdpictureOCR.AddLanguage(OCRLanguage.English)
'Set up the OCR context and the character list.
gdpictureOCR.Context = OCRContext.OCRContextSingleBlock
gdpictureOCR.CharacterSet = ""
'Run the OCR process.
Dim resID As String = gdpictureOCR.RunOCR()
If gdpictureOCR.GetStat = GdPictureStatus.OK Then
Dim linesCount As Integer = gdpictureOCR.GetTextLineCount(resID)
If gdpictureOCR.GetStat() = GdPictureStatus.OK Then
message = message + "The number of recognized text lines: " + linesCount.ToString() + vbCrLf
Dim line As String = ""
For i As Integer = 0 To linesCount - 1
message = message + i.ToString() + ":"
line = gdpictureOCR.GetTextLineValue(resID, i)
If gdpictureOCR.GetStat() = GdPictureStatus.OK Then
message = message + line
Else
message = message + gdpictureOCR.GetStat().ToString()
End If
message += vbCrLf
Next
MessageBox.Show(message, caption)
'Continue with analyzing the result ...
Else
MessageBox.Show("The GetTextLineCount() method has failed with the status: " + gdpictureOCR.GetStat().ToString())
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: GetTextLineValue";
GdPictureOCR gdpictureOCR = new GdPictureOCR();
GdPicturePDF gdpicturePDF = new GdPicturePDF();
//Load the PDF document.
if (gdpicturePDF.LoadFromFile("input.pdf", false) == GdPictureStatus.OK)
{
//Set the new origin for better coordinates handling.
gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft);
gdpicturePDF.SetLineColor(Color.Olive);
gdpicturePDF.SetLineWidth(2);
//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.
{
string message = "";
//Set up the OCR parameters.
gdpictureOCR.ResourcesFolder = "C:\\Path\\To\\GdPicture.NET 14\\Redist\\OCR";
gdpictureOCR.AddLanguage(OCRLanguage.English);
//Set up the OCR context and the character list.
gdpictureOCR.Context = OCRContext.OCRContextSingleBlock;
gdpictureOCR.CharacterSet = "";
//Run the OCR process.
string resID = gdpictureOCR.RunOCR();
if (gdpictureOCR.GetStat() == GdPictureStatus.OK)
{
int linesCount = gdpictureOCR.GetTextLineCount(resID);
if (gdpictureOCR.GetStat() == GdPictureStatus.OK)
{
message = message + "The number of recognized text lines: " + linesCount.ToString() + "\n";
string line = "";
for (int i = 0; i < linesCount; i++)
{
message = message + i.ToString() + ":";
line = gdpictureOCR.GetTextLineValue(resID, i);
if (gdpictureOCR.GetStat() == GdPictureStatus.OK) message = message + line;
else message = message + gdpictureOCR.GetStat().ToString();
message += "\n";
}
MessageBox.Show(message, caption);
//Continue with analyzing the result ...
}
else
MessageBox.Show("The GetTextLineCount() method has failed with the status: " + gdpictureOCR.GetStat().ToString());
}
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();
Example
How to find out the recognized lines.
Dim caption As String = "Example: GetTextLineValue"
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
'Set the new origin for better coordinates handling.
gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft)
gdpicturePDF.SetLineColor(Color.Olive)
gdpicturePDF.SetLineWidth(2)
'Select the first page.
gdpicturePDF.SelectPage(1)
'Render this page to a 200 DPI image.
Dim image As Integer = gdpicturePDF.RenderPageToGdPictureImage(200, True)
If gdpicturePDF.GetStat = GdPictureStatus.OK AndAlso
gdpictureOCR.SetImage(image) = GdPictureStatus.OK Then
'Setting up the image is mandatory.
Dim message As String = Nothing
'Set up the OCR parameters.
gdpictureOCR.ResourcesFolder = "C:\Path\To\GdPicture.NET 14\Redist\OCR"
gdpictureOCR.AddLanguage(OCRLanguage.English)
'Set up the OCR context and the character list.
gdpictureOCR.Context = OCRContext.OCRContextSingleBlock
gdpictureOCR.CharacterSet = ""
'Run the OCR process.
Dim resID As String = gdpictureOCR.RunOCR()
If gdpictureOCR.GetStat = GdPictureStatus.OK Then
Dim linesCount As Integer = gdpictureOCR.GetTextLineCount(resID)
If gdpictureOCR.GetStat() = GdPictureStatus.OK Then
message = message + "The number of recognized text lines: " + linesCount.ToString() + vbCrLf
Dim line As String = ""
For i As Integer = 0 To linesCount - 1
message = message + i.ToString() + ":"
line = gdpictureOCR.GetTextLineValue(resID, i)
If gdpictureOCR.GetStat() = GdPictureStatus.OK Then
message = message + line
Else
message = message + gdpictureOCR.GetStat().ToString()
End If
message += vbCrLf
Next
MessageBox.Show(message, caption)
'Continue with analyzing the result ...
Else
MessageBox.Show("The GetTextLineCount() method has failed with the status: " + gdpictureOCR.GetStat().ToString())
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: GetTextLineValue";
GdPictureOCR gdpictureOCR = new GdPictureOCR();
GdPicturePDF gdpicturePDF = new GdPicturePDF();
//Load the PDF document.
if (gdpicturePDF.LoadFromFile("input.pdf", false) == GdPictureStatus.OK)
{
//Set the new origin for better coordinates handling.
gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft);
gdpicturePDF.SetLineColor(Color.Olive);
gdpicturePDF.SetLineWidth(2);
//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.
{
string message = "";
//Set up the OCR parameters.
gdpictureOCR.ResourcesFolder = "C:\\Path\\To\\GdPicture.NET 14\\Redist\\OCR";
gdpictureOCR.AddLanguage(OCRLanguage.English);
//Set up the OCR context and the character list.
gdpictureOCR.Context = OCRContext.OCRContextSingleBlock;
gdpictureOCR.CharacterSet = "";
//Run the OCR process.
string resID = gdpictureOCR.RunOCR();
if (gdpictureOCR.GetStat() == GdPictureStatus.OK)
{
int linesCount = gdpictureOCR.GetTextLineCount(resID);
if (gdpictureOCR.GetStat() == GdPictureStatus.OK)
{
message = message + "The number of recognized text lines: " + linesCount.ToString() + "\n";
string line = "";
for (int i = 0; i < linesCount; i++)
{
message = message + i.ToString() + ":";
line = gdpictureOCR.GetTextLineValue(resID, i);
if (gdpictureOCR.GetStat() == GdPictureStatus.OK) message = message + line;
else message = message + gdpictureOCR.GetStat().ToString();
message += "\n";
}
MessageBox.Show(message, caption);
//Continue with analyzing the result ...
}
else
MessageBox.Show("The GetTextLineCount() method has failed with the status: " + gdpictureOCR.GetStat().ToString());
}
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();
See Also