Example





In This Topic
GdPicture14 Namespace / GdPicturePDF Class / GetPageHeight Method

GetPageHeight Method (GdPicturePDF)

In This Topic
Returns the page height of the currently selected page in the loaded PDF document expressed in the current units used in this document.

You can simply use the GetMeasurementUnit method to determine the currently defined units or you can easily use the SetMeasurementUnit method to reset the units according to your preference.

Syntax
'Declaration

 

Public Function GetPageHeight() As Single
public float GetPageHeight()
public function GetPageHeight(): Single; 
public function GetPageHeight() : float;
public: float GetPageHeight(); 
public:

float GetPageHeight(); 

Return Value

The page height expressed in the current units specified by the SetMeasurementUnit method. The GetStat method can be subsequently used to determine if this method has been successful.

Be aware that any potential page rotation is not respected. The returned value is always the original page height value, that has been set when adding the page.

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.

Example
How to find out the page height of the currently selected page in the loaded PDF document. This example shows you that the page rotation is not respected when determining the page height.
Dim caption As String = "Example: GetPageHeight"

Dim gdpicturePDF As New GdPicturePDF()

If gdpicturePDF.NewPDF() = GdPictureStatus.OK Then

    Dim status As GdPictureStatus = gdpicturePDF.NewPage(PdfPageSizes.PdfPageSizeA4) 'A4 = (210mm x 270mm)

    If status = GdPictureStatus.OK Then

        gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft)

        gdpicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitMillimeter)

        Dim height As Single = gdpicturePDF.GetPageHeight()

        status = gdpicturePDF.GetStat()

        If status = GdPictureStatus.OK Then

            MessageBox.Show("The height of the current page is " + height.ToString() + " mm.", caption)

        Else

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

        End If

            

        status = gdpicturePDF.RotatePage(90)

        If status = GdPictureStatus.OK Then

            height = gdpicturePDF.GetPageHeight()

            status = gdpicturePDF.GetStat()

            If status = GdPictureStatus.OK Then

                MessageBox.Show("The height of the current page after the rotation is " + height.ToString() + " mm.", caption)

            Else

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

            End If

        Else

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

        End If

    Else

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

    End If

Else

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

End If

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

GdPicturePDF gdpicturePDF = new GdPicturePDF();

if (gdpicturePDF.NewPDF() == GdPictureStatus.OK)

{

    GdPictureStatus status = gdpicturePDF.NewPage(PdfPageSizes.PdfPageSizeA4); //A4 = (210mm x 270mm)

    if (status == GdPictureStatus.OK)

    {

        gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft);

        gdpicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitMillimeter);

        float height = gdpicturePDF.GetPageHeight();

        status = gdpicturePDF.GetStat();

        if (status == GdPictureStatus.OK)

            MessageBox.Show("The height of the current page is " + height.ToString() + " mm." , caption);

        else

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

            

        status = gdpicturePDF.RotatePage(90);

        if (status == GdPictureStatus.OK)

        {

            height = gdpicturePDF.GetPageHeight();

            status = gdpicturePDF.GetStat();

            if (status == GdPictureStatus.OK)

                MessageBox.Show("The height of the current page after the rotation is " + height.ToString() + " mm.", caption);

            else

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

        }

        else

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

    }

    else

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

}

else

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

gdpicturePDF.Dispose();
See Also