Example





In This Topic
GdPicture14 Namespace / GdPicturePDF Class / GetPageRotation Method

GetPageRotation Method (GdPicturePDF)

In This Topic
Returns the actual page rotation in the clockwise direction, in degrees, of the currently selected page in the loaded PDF document.

This value expresses the number of degrees by which the current page should be rotated clockwise when displayed or printed. It must always be a multiple of 90.

Syntax
'Declaration

 

Public Function GetPageRotation() As Integer
public int GetPageRotation()
public function GetPageRotation(): Integer; 
public function GetPageRotation() : int;
public: int GetPageRotation(); 
public:

int GetPageRotation(); 

Return Value

The clockwise rotation of the currently selected page in degrees. The returned value can only be 0, 90, 180 or 270. 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.

Just to warn you that in spite of the methods GetPageRotation() and AddPageRotation() are named similarly, they work with different data. Please see the AddPageRotation method for more details about the differences.

Example
How to determine the actual page rotation in degrees. In this example each page of the currently loaded PDF document has been rotated step by step by its page number multiple of 90 degrees.
Dim caption As String = "Example: GetPageRotation"

Dim gdpicturePDF As New GdPicturePDF()

If gdpicturePDF.LoadFromFile("test.pdf", False) = GdPictureStatus.OK Then

    Dim count As Integer = gdpicturePDF.GetPageCount()

    Dim status As GdPictureStatus = gdpicturePDF.GetStat()

    If status = GdPictureStatus.OK Then

        For i As Integer = 1 To count

            status = gdpicturePDF.SelectPage(i)

            If status = GdPictureStatus.OK Then

                status = gdpicturePDF.RotatePage(i * 90)

                If status = GdPictureStatus.OK Then

                    Dim rotation As Integer = gdpicturePDF.GetPageRotation()

                    status = gdpicturePDF.GetStat()

                    If status = GdPictureStatus.OK Then

                        MessageBox.Show("The rotation angle of the page nr." + i.ToString() + " is " + rotation.ToString() + " degrees.", caption)

                    Else

                        MessageBox.Show("The GetPageRotation() method has failed with the status: " + status.ToString(), caption)

                    End If

                    If i = count Then

                        If gdpicturePDF.SaveToFile("test_GetPageRotation.pdf") = GdPictureStatus.OK Then

                            MessageBox.Show("The pages have been rotated successfully and the file has been saved.", caption)

                        Else

                            MessageBox.Show("The pages have been rotated successfully but the file can't be saved.", caption)

                        End If

                    End If

                Else

                    MessageBox.Show("The RotatePage() method has failed with the status: " + status.ToString(), caption)

                    Exit For

                End If

            Else

                MessageBox.Show("The SelectPage() method has failed with the status: " + status.ToString(), caption)

                Exit For

            End If

        Next

    Else

        MessageBox.Show("The GetPageCount() method has failed with the status: " + status.ToString(), caption)

    End If

Else

    MessageBox.Show("The file can't be loaded.", caption)

End If

gdpicturePDF.Dispose()
string caption = "Example: GetPageRotation";

GdPicturePDF gdpicturePDF = new GdPicturePDF();

if (gdpicturePDF.LoadFromFile("test.pdf", false) == GdPictureStatus.OK)

{

    int count = gdpicturePDF.GetPageCount();

    GdPictureStatus status = gdpicturePDF.GetStat();

    if (status == GdPictureStatus.OK)

    {

        for (int i = 1; i <= count; i++)

        {

            status = gdpicturePDF.SelectPage(i);

            if (status == GdPictureStatus.OK)

            {

                status = gdpicturePDF.RotatePage(i*90);

                if (status == GdPictureStatus.OK)

                {

                    int rotation = gdpicturePDF.GetPageRotation();

                    status = gdpicturePDF.GetStat();

                    if (status == GdPictureStatus.OK)

                        MessageBox.Show("The rotation angle of the page nr." + i.ToString() + " is " + rotation.ToString() + " degrees.", caption);

                    else

                        MessageBox.Show("The GetPageRotation() method has failed with the status: " + status.ToString(), caption);

                    if (i == count)

                    {

                        if (gdpicturePDF.SaveToFile("test_GetPageRotation.pdf") == GdPictureStatus.OK)

                            MessageBox.Show("The pages have been rotated successfully and the file has been saved.", caption);

                        else

                            MessageBox.Show("The pages have been rotated successfully but the file can't be saved.", caption);

                    }

                }

                else

                {

                    MessageBox.Show("The RotatePage() method has failed with the status: " + status.ToString(), caption);

                    break;

                }

            }

            else

            {

                MessageBox.Show("The SelectPage() method has failed with the status: " + status.ToString(), caption);

                break;

            }

        }

    }

    else

        MessageBox.Show("The GetPageCount() method has failed with the status: " + status.ToString(), caption);

}

else

    MessageBox.Show("The file can't be loaded.", caption);

gdpicturePDF.Dispose();
See Also