The 0-based index of the image within the current page. It must be a value from 0 to GetPageImageCount-1.
Output parameter. The width of the specified image, in pixels.
Output parameter. The height of the specified image, in pixels.
Example





In This Topic
GdPicture14 Namespace / GdPicturePDF Class / GetPageImageSize Method

GetPageImageSize Method (GdPicturePDF)

In This Topic
Returns the width and the height of an image, specified by its index within the currently selected page of the loaded PDF document. Both dimensions are constantly expressed in pixels.
Syntax
'Declaration

 

Public Function GetPageImageSize( _

   ByVal ImageIdx As Integer, _

   ByRef Width As Integer, _

   ByRef Height As Integer _

) As GdPictureStatus
public GdPictureStatus GetPageImageSize( 

   int ImageIdx,

   ref int Width,

   ref int Height

)
public function GetPageImageSize( 

    ImageIdx: Integer;

   var  Width: Integer;

   var  Height: Integer

): GdPictureStatus; 
public function GetPageImageSize( 

   ImageIdx : int,

   Width : int,

   Height : int

) : GdPictureStatus;
public: GdPictureStatus GetPageImageSize( 

   int ImageIdx,

   ref int Width,

   ref int Height

) 
public:

GdPictureStatus GetPageImageSize( 

   int ImageIdx,

   int% Width,

   int% Height

) 

Parameters

ImageIdx
The 0-based index of the image within the current page. It must be a value from 0 to GetPageImageCount-1.
Width
Output parameter. The width of the specified image, in pixels.
Height
Output parameter. The height of the specified image, in pixels.

Return Value

A member of the GdPictureStatus enumeration. If the method has been successfully followed, then the return value is GdPictureStatus.OK.

We strongly recommend always checking this status first.

Remarks
This method is only allowed for use with non-encrypted documents.

Be aware that the width and the height parameters are the original dimensions of the image resource added to the current document, just before the image itself has been drawn.

Example
How to redraw all images from the first page of the PDF document to one image per new page within the same document using the image dimensions.
Dim caption As String = "Example: GetPageImageSize"

Dim gdpicturePDF As New GdPicturePDF()

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

    Dim pageCount As Integer = gdpicturePDF.GetPageCount()

    Dim status As GdPictureStatus = gdpicturePDF.GetStat()

    If (status = GdPictureStatus.OK) AndAlso (pageCount > 0) Then

        'The first page is automatically selected as the current page.

        Dim imageCount As Integer = gdpicturePDF.GetPageImageCount()

        status = gdpicturePDF.GetStat()

        If (status = GdPictureStatus.OK) AndAlso (imageCount > 0) Then

            Dim message As String = ""

            Dim imageResName As String = ""

            Dim width As Integer = 0, height As Integer = 0

            For i As Integer = 0 To imageCount - 1

                imageResName = gdpicturePDF.GetPageImageResName(i)

                status = gdpicturePDF.GetStat()

                If status = GdPictureStatus.OK Then

                    If (gdpicturePDF.GetPageImageSize(i, width, height) = GdPictureStatus.OK) AndAlso

                       (gdpicturePDF.NewPage(PdfPageSizes.PdfPageSizeA4) = GdPictureStatus.OK) AndAlso

                       (gdpicturePDF.DrawImage(imageResName, 0, 0, width, height) = GdPictureStatus.OK) AndAlso

                       (gdpicturePDF.SelectPage(1) = GdPictureStatus.OK) Then

                        'We need to move again to the page nr.1 because the newly added page is selected after drawing.

                        message = message + "The image indexed as " + i.ToString() + " with the dimensions [width = " + width.ToString() + ", height = " + height.ToString() + "] has been drawn successfully." + vbCrLf

                    Else

                        message = message + "The image indexed as " + i.ToString() + " has failed to draw with the status: " + gdpicturePDF.GetStat().ToString() + vbCrLf

                    End If

                Else

                    message = message + "The GetPageImageResName() method has failed with the status: " + status.ToString()

                End If

            Next

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

                message = message + "The file has been saved successfully."

            Else

                message = message + "The file has not been saved successfully."

            End If

            MessageBox.Show(message, caption)

        Else

            If status = GdPictureStatus.OK Then

                MessageBox.Show("The first page doesn't contain any image.", caption)

            Else

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

            End If

        End If

    Else

        If status = GdPictureStatus.OK Then

            MessageBox.Show("This file doesn't contain any page.", caption)

        Else

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

        End If

    End If

Else

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

End If

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

GdPicturePDF gdpicturePDF = new GdPicturePDF();

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

{

    int pageCount = gdpicturePDF.GetPageCount();

    GdPictureStatus status = gdpicturePDF.GetStat();

    if ((status == GdPictureStatus.OK) && (pageCount > 0))

    {

        //The first page is automatically selected as the current page.

        int imageCount = gdpicturePDF.GetPageImageCount();

        status = gdpicturePDF.GetStat();

        if ((status == GdPictureStatus.OK) && (imageCount > 0))

        {

            string message = "";

            string imageResName = "";

            int width = 0, height = 0;

            for (int i = 0; i < imageCount; i++)

            {

                imageResName = gdpicturePDF.GetPageImageResName(i);

                status = gdpicturePDF.GetStat();

                if (status == GdPictureStatus.OK)

                {

                    if ((gdpicturePDF.GetPageImageSize(i, ref width, ref height) == GdPictureStatus.OK) &&

                        (gdpicturePDF.NewPage(PdfPageSizes.PdfPageSizeA4) == GdPictureStatus.OK) &&

                        (gdpicturePDF.DrawImage(imageResName, 0, 0, width, height) == GdPictureStatus.OK) &&

                        (gdpicturePDF.SelectPage(1) == GdPictureStatus.OK))

                    {

                        //We need to move again to the page nr.1 because the newly added page is selected after drawing.

                        message = message + "The image indexed as " + i.ToString() + " with the dimensions [width = " + width.ToString() + ", height = " + height.ToString() + "] has been drawn successfully.\n";

                    }

                    else

                        message = message + "The image indexed as " + i.ToString() + " has failed to draw with the status: " + gdpicturePDF.GetStat().ToString() + "\n";

                }

                else

                    message = message + "The GetPageImageResName() method has failed with the status: " + status.ToString();

            }

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

                message = message + "The file has been saved successfully.";

            else

                message = message + "The file has not been saved successfully.";

            MessageBox.Show(message, caption);

        }

        else

        {

            if (status == GdPictureStatus.OK)

                MessageBox.Show("The first page doesn't contain any image.", caption);

            else

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

        }

    }

    else

    {

        if (status == GdPictureStatus.OK)

            MessageBox.Show("This file doesn't contain any page.", caption);

        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