GdPicture.NET.14
GdPicture14 Namespace / GdPicturePDF Class / AutoDeskew Method
Maximum skew angle set for providing the subsequent research. For example, use the value of 10 to achieve deskiewing the page with a skew angle ±10 degrees. It is recommended to use a value lower than 15.
Determines if the engine must be optimistic in the skew detection. Set this parameter to true if you are sure that the current page has a skew. Otherwise set it to false.
Example





In This Topic
AutoDeskew Method (GdPicturePDF)
In This Topic
Deskews the current page in the loaded PDF document and returns the calculated skew angle, in degrees. The page is subsequently rotated using this angle to correct the possible skewing if present.

Deskewing a page can help a lot to do OCR, OMR, barcode detection or just improve the reliability of the page itself. You can benefit from using this method especially for documents mixing vector and raster content.

Syntax
'Declaration
 
Public Function AutoDeskew( _
   ByVal MaxAngleOfResearch As Single, _
   ByVal Optimistic As Boolean _
) As Single
public float AutoDeskew( 
   float MaxAngleOfResearch,
   bool Optimistic
)
public function AutoDeskew( 
    MaxAngleOfResearch: Single;
    Optimistic: Boolean
): Single; 
public function AutoDeskew( 
   MaxAngleOfResearch : float,
   Optimistic : boolean
) : float;
public: float AutoDeskew( 
   float MaxAngleOfResearch,
   bool Optimistic
) 
public:
float AutoDeskew( 
   float MaxAngleOfResearch,
   bool Optimistic
) 

Parameters

MaxAngleOfResearch
Maximum skew angle set for providing the subsequent research. For example, use the value of 10 to achieve deskiewing the page with a skew angle ±10 degrees. It is recommended to use a value lower than 15.
Optimistic
Determines if the engine must be optimistic in the skew detection. Set this parameter to true if you are sure that the current page has a skew. Otherwise set it to false.

Return Value

The skew angle of the currently selected page, in degrees, between -MaxAngleOfResearch and +MaxAngleOfResearch. The GetStat method can be subsequently used to determine if this method has been successful.
Remarks
This method is only allowed for use with non-encrypted documents.

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

Be aware that the resulting skew angle can be between -MaxAngleOfResearch and +MaxAngleOfResearch, where negative values indicate counterclockwise and positive values indicate a clockwise rotation.

Example
How to autodeskew the pages in the PDF document.
Dim caption As String = "Example: AutoDeskew"
Using pdf As GdPicturePDF = New GdPicturePDF()
    Dim message As String = ""
    Dim status As GdPictureStatus = pdf.LoadFromFile("source.pdf", False)
    If status = GdPictureStatus.OK Then
        Dim pageCount As Integer = pdf.GetPageCount()
        status = pdf.GetStat()
        Dim pageNo As Integer = 1
        While (pageNo <= pageCount) AndAlso (status = GdPictureStatus.OK)
            status = pdf.SelectPage(pageNo)
            If status = GdPictureStatus.OK Then
                Dim angle As Single = pdf.AutoDeskew(15, False)
                status = pdf.GetStat()
                If status = GdPictureStatus.OK Then
                    message += "PageNo " + pageNo.ToString() + ".  - skew angle = " + angle.ToString() + vbCrLf
                Else
                    message += "PageNo " + pageNo.ToString() + ".  - status: " + status.ToString() + vbCrLf
                End If
            End If
            pageNo += 1
        End While
        If status = GdPictureStatus.OK Then
            status = pdf.SaveToFile("dest.pdf")
            If status = GdPictureStatus.OK Then
                MessageBox.Show(message + vbCrLf + "The file has been saved.", caption)
            Else
                MessageBox.Show(message + vbCrLf + "The example has been followed successfully, but the file can't be saved. Status: " + status.ToString(), caption)
            End If
        Else
            MessageBox.Show("The example has NOT been followed successfully. Status: " + status.ToString(), caption)
        End If
    Else
        MessageBox.Show("The file can't be loaded. Status: " + status.ToString(), caption)
    End If
End Using
string caption = "Example: AutoDeskew";
using (GdPicturePDF pdf = new GdPicturePDF())
{
    string message = "";
    GdPictureStatus status = pdf.LoadFromFile("source.pdf", false);
    if (status == GdPictureStatus.OK)
    {
        int pageCount = pdf.GetPageCount();
        status = pdf.GetStat();
        for (int pageNo = 1; (pageNo <= pageCount) && (status == GdPictureStatus.OK); pageNo++)
        {
            status = pdf.SelectPage(pageNo);
            if (status == GdPictureStatus.OK)
            {
                float angle = pdf.AutoDeskew(15, false);
                status = pdf.GetStat();
                if (status == GdPictureStatus.OK)
                    message += "PageNo " + pageNo.ToString() + ".  - skew angle = " + angle.ToString() + "\n";
                else
                    message += "PageNo " + pageNo.ToString() + ".  - status: " + status.ToString() + "\n";
            }
        }
        if (status == GdPictureStatus.OK)
        {
            status = pdf.SaveToFile("dest.pdf");
            if (status == GdPictureStatus.OK)
                MessageBox.Show(message + "\nThe file has been saved.", caption);
            else
                MessageBox.Show(message + "\nThe example has been followed successfully, but the file can't be saved. Status: " + status.ToString(), caption);
        }
        else
            MessageBox.Show("The example has NOT been followed successfully. Status: " + status.ToString(), caption);
    }
    else
        MessageBox.Show("The file can't be loaded. Status: " + status.ToString(), caption);
}
See Also