GdPicture.NET.14.API
GdPicture14 Namespace / GdPictureOCR Class / GetParagraphBlockIndex Method
The unique result identifier of the executed OCR process obtained by the GdPictureOCR.RunOCR method.
The 0-based index of the paragraph within the specified OCR result. It must be a value between 0 and GdPictureOCR.GetParagraphCount(OCRResultID) - 1.
Example





In This Topic
GetParagraphBlockIndex Method (GdPictureOCR)
In This Topic
Returns the index of the block, which incorporates the specified paragraph, that is a part of a specified OCR result.
Syntax
'Declaration
 
Public Function GetParagraphBlockIndex( _
   ByVal OCRResultID As String, _
   ByVal ParagraphIdx As Integer _
) As Integer
public int GetParagraphBlockIndex( 
   string OCRResultID,
   int ParagraphIdx
)
public function GetParagraphBlockIndex( 
    OCRResultID: String;
    ParagraphIdx: Integer
): Integer; 
public function GetParagraphBlockIndex( 
   OCRResultID : String,
   ParagraphIdx : int
) : int;
public: int GetParagraphBlockIndex( 
   string* OCRResultID,
   int ParagraphIdx
) 
public:
int GetParagraphBlockIndex( 
   String^ OCRResultID,
   int ParagraphIdx
) 

Parameters

OCRResultID
The unique result identifier of the executed OCR process obtained by the GdPictureOCR.RunOCR method.
ParagraphIdx
The 0-based index of the paragraph within the specified OCR result. It must be a value between 0 and GdPictureOCR.GetParagraphCount(OCRResultID) - 1.

Return Value

The index of the block, which involves the required paragraph. Please always use the GdPictureOCR.GetStat method to determine if this method has been successful.
Remarks
It is recommend to use the GdPictureOCR.GetStat method to identify the specific reason for the method's failure, if any.
Example
How to determine, which paragraph belongs to which block in the OCR result.
Dim caption As String = "Example: GetParagraphBlockIndex"
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
        Dim message As String = ""
        '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.OCRContextDocument
        gdpictureOCR.CharacterSet = ""
        'Run the OCR process.
        Dim resID As String = gdpictureOCR.RunOCR()
        If gdpictureOCR.GetStat() = GdPictureStatus.OK Then
            Dim blockCount As Integer = gdpictureOCR.GetBlockCount(resID)
            If gdpictureOCR.GetStat() = GdPictureStatus.OK Then
                message = message + "The number of all recognized blocks: " + blockCount.ToString() + vbCrLf
                Dim paragraphCount As Integer = gdpictureOCR.GetParagraphCount(resID)
                If gdpictureOCR.GetStat() = GdPictureStatus.OK Then
                    message = message + "The number of all recognized paragraphs: " + paragraphCount.ToString() + vbCrLf
                    For i As Integer = 0 To paragraphCount - 1
                        message = message + "The paragraph nr." + i.ToString() + " is included in the block nr." +
                                            gdpictureOCR.GetParagraphBlockIndex(resID, i).ToString() = "." + vbCrLf
                    Next
                    MessageBox.Show(message, caption)
                    'Continue with analyzing the result ...
                Else
                    MessageBox.Show("The GetParagraphCount() method has failed with the status: " + gdpictureOCR.GetStat().ToString())
                End If
            Else
                MessageBox.Show("The GetBlockCount() 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: GetParagraphBlockIndex";
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.
    {
        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.OCRContextDocument;
        gdpictureOCR.CharacterSet = "";
        //Run the OCR process.
        string resID = gdpictureOCR.RunOCR();
        if (gdpictureOCR.GetStat() == GdPictureStatus.OK)
        {
            int blockCount = gdpictureOCR.GetBlockCount(resID);
            if (gdpictureOCR.GetStat() == GdPictureStatus.OK)
            {
                message = message + "The number of all recognized blocks: " + blockCount.ToString() + "\n";
                int paragraphCount = gdpictureOCR.GetParagraphCount(resID);
                if (gdpictureOCR.GetStat() == GdPictureStatus.OK)
                {
                    message = message + "The number of all recognized paragraphs: " + paragraphCount.ToString() + "\n";
                    for (int i = 0; i < paragraphCount; i++)
                    {
                        message = message + "The paragraph nr." + i.ToString() + " is included in the block nr." +
                                           gdpictureOCR.GetParagraphBlockIndex(resID, i).ToString() + ".\n";
                    }
                    MessageBox.Show(message, caption);
                    //Continue with analyzing the result ...
                }
                else
                    MessageBox.Show("The GetParagraphCount() method has failed with the status: " + gdpictureOCR.GetStat().ToString());
            }
            else
                MessageBox.Show("The GetBlockCount() 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