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





In This Topic
GetParagraphTop Method (GdPictureOCR)
In This Topic
Returns the top y-coordinate of the bounding box of the specified paragraph, that is a part of a specified OCR result.

This method uses a coordinate system, where the origin is in the top-left corner of the processed image and the units are pixels.

Syntax
'Declaration
 
Public Function GetParagraphTop( _
   ByVal OCRResultID As String, _
   ByVal ParagraphIdx As Integer _
) As Integer
public int GetParagraphTop( 
   string OCRResultID,
   int ParagraphIdx
)
public function GetParagraphTop( 
    OCRResultID: String;
    ParagraphIdx: Integer
): Integer; 
public function GetParagraphTop( 
   OCRResultID : String,
   ParagraphIdx : int
) : int;
public: int GetParagraphTop( 
   string* OCRResultID,
   int ParagraphIdx
) 
public:
int GetParagraphTop( 
   String^ OCRResultID,
   int ParagraphIdx
) 

Parameters

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

Return Value

The top y-coordinate of the paragraph's bounding box, in pixels.

Please always use the GetStat method to determine if this method has been successful.

Remarks
It is recommend to use the GetStat method to identify the specific reason for the method's failure, if any.

Please note, that the origin of the used coordinate system is in the top-left corner of the processed image and the used units are pixels.

Example
How to find out the number of recognized paragraphs within the OCR result and some of the paragraph's properties.
Dim caption As String = "Example: GetParagraphTop"
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 paragraphCount As Integer = gdpictureOCR.GetParagraphCount(resID)
            If gdpictureOCR.GetStat() = GdPictureStatus.OK Then
                message = message + "The number of recognized paragraphs: " + paragraphCount.ToString() + vbCrLf
                For i As Integer = 0 To paragraphCount - 1
                    message = message + "The paragraph nr." + i.ToString() + " contains " + gdpictureOCR.GetParagraphTextLineCount(resID, i).ToString() + " text lines." + vbCrLf
                    message = message + "   The paragraph is justified: " + gdpictureOCR.GetParagraphJustification(resID, i).ToString()
                    message = message + "   The first text line index is " + gdpictureOCR.GetParagraphFirstTextLineIndex(resID, i).ToString() + "." + vbCrLf
                    Dim left As Integer = gdpictureOCR.GetTextLineLeft(resID, i)
                    Dim top As Integer = gdpictureOCR.GetTextLineTop(resID, i)
                    If gdpicturePDF.DrawRectangle(left, top, gdpictureOCR.GetTextLineRight(resID, i) - left, gdpictureOCR.GetTextLineBottom(resID, i) - top, False, True) = GdPictureStatus.OK Then
                        message = message + "   Drawn: yes" + vbCrLf
                    Else
                        message = message + "   Drawn: no" + vbCrLf
                    End If
                Next
                MessageBox.Show(message, caption)
                'Continue with analyzing the result ...
                'Save the page with drawn recognized paragraphs to the new PDF document.
                If gdpicturePDF.SaveToFile("output.pdf") = GdPictureStatus.OK Then
                    MessageBox.Show("Done!", caption)
                Else
                    MessageBox.Show("The file can't be saved. Status: " + gdpicturePDF.GetStat().ToString(), caption)
                End If
            Else
                MessageBox.Show("The GetParagraphCount() 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: GetParagraphTop";
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 paragraphCount = gdpictureOCR.GetParagraphCount(resID);
            if (gdpictureOCR.GetStat() == GdPictureStatus.OK)
            {
                message = message + "The number of recognized paragraphs: " + paragraphCount.ToString() + "\n";
                for (int i = 0; i < paragraphCount; i++)
                {
                    message = message + "The paragraph nr." + i.ToString() + " contains " + gdpictureOCR.GetParagraphTextLineCount(resID, i).ToString() + " text lines.\n";
                    message = message + "   The paragraph is justified: " + gdpictureOCR.GetParagraphJustification(resID, i).ToString();
                    message = message + "   The first text line index is " + gdpictureOCR.GetParagraphFirstTextLineIndex(resID, i).ToString() + ".\n";
                    int left = gdpictureOCR.GetParagraphLeft(resID, i);
                    int top = gdpictureOCR.GetParagraphTop(resID, i);
                    if (gdpicturePDF.DrawRectangle(left, top, gdpictureOCR.GetParagraphRight(resID, i) - left, gdpictureOCR.GetParagraphBottom(resID, i) - top, false, true) == GdPictureStatus.OK)
                        message = message + "   Drawn: yes\n";
                    else
                        message = message + "   Drawn: no\n";
                }
                MessageBox.Show(message, caption);
                //Continue with analyzing the result ...
                //Save the page with drawn recognized paragraphs to the new PDF document.
                if (gdpicturePDF.SaveToFile("output.pdf") == GdPictureStatus.OK)
                    MessageBox.Show("Done!", caption);
                else
                    MessageBox.Show("The file can't be saved. Status: " + gdpicturePDF.GetStat().ToString(), caption);
            }
            else
                MessageBox.Show("The GetParagraphCount() 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