The image number of the required image within the current page. It must be a value from 1 to GetPageImageCount.
Example





In This Topic
GdPicture14 Namespace / GdPicturePDF Class / ExtractPageImage Method

ExtractPageImage Method (GdPicturePDF)

In This Topic
Extracts an image, specified by its number within the currently selected page of the loaded PDF document, into a new GdPictureImage object. The specified image is extracted as a resource to an object of the type GdPictureImage, in other words the image resource becomes independent of the source document. The image is clearly recognizable by the returned unique image identifier and it can be subsequently used outside the source document, for example, you can add this image into another PDF document. It is also possible to take advantages of the GdPictureImaging class and its methods for further manipulation with this image.
Syntax
'Declaration

 

Public Function ExtractPageImage( _

   ByVal ImageNo As Integer _

) As Integer
public int ExtractPageImage( 

   int ImageNo

)
public function ExtractPageImage( 

    ImageNo: Integer

): Integer; 
public function ExtractPageImage( 

   ImageNo : int

) : int;
public: int ExtractPageImage( 

   int ImageNo

) 
public:

int ExtractPageImage( 

   int ImageNo

) 

Parameters

ImageNo
The image number of the required image within the current page. It must be a value from 1 to GetPageImageCount.

Return Value

A unique image identifier of the newly created image object of the type GdPictureImage. The GetStat method can be subsequently used to determine if this method has been successful.

Just to remind you that you need to release the image after being used, for example, using the static DisposeImage method.

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 extract all images from the first page of the source PDF document to the newly created destination PDF document. All images are drawn one image per page.
Dim caption As String = "Example: ExtractPageImage"

Dim gdpicturePDFSrc As New GdPicturePDF()

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

    Dim pageCount As Integer = gdpicturePDFSrc.GetPageCount()

    Dim status As GdPictureStatus = gdpicturePDFSrc.GetStat()

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

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

        Dim imageCount As Integer = gdpicturePDFSrc.GetPageImageCount()

        status = gdpicturePDFSrc.GetStat()

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

            Dim gdpicturePDFDest As New GdPicturePDF()

            If gdpicturePDFDest.NewPDF() = GdPictureStatus.OK Then

                Dim message As String = ""

                Dim imageID As Integer = 0

                For i As Integer = 1 To imageCount

                    imageID = gdpicturePDFSrc.ExtractPageImage(i)

                    status = gdpicturePDFSrc.GetStat()

                    If status = GdPictureStatus.OK Then

                        Dim res_name As String = gdpicturePDFDest.AddImageFromGdPictureImage(imageID, False, True)

                        status = gdpicturePDFSrc.GetStat()

                        If status = GdPictureStatus.OK Then

                            message = message + "The image nr. " + i.ToString() + " has been successfully drawn." + vbCrLf

                        Else

                            message = message + "The AddImageFromGdPictureImage() method has failed for the image nr. " + i.ToString() + " with the status: " + status.ToString() + vbCrLf

                        End If

                        If GdPictureDocumentUtilities.DisposeImage(imageID) <> GdPictureStatus.OK Then

                            message = message + "The DisposeImage() method has failed for the image nr. " + i.ToString() + " with the status: " + status.ToString() + vbCrLf

                        End If

                    Else

                        message = message + "The ExtractPageImage() method has failed for the image nr. " + i.ToString() + " with the status: " + status.ToString() + vbCrLf

                    End If

                Next

                If gdpicturePDFDest.SaveToFile("test_ExtractPageImage.pdf") = GdPictureStatus.OK Then

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

                Else

                    message = message + "The file can't be saved. Status: " + gdpicturePDFDest.GetStat().ToString()

                End If

                MessageBox.Show(message, caption)

            Else

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

            End If

            gdpicturePDFDest.Dispose()

        Else

            If status = GdPictureStatus.OK Then

                MessageBox.Show("This file 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("The first page 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

gdpicturePDFSrc.Dispose()
string caption = "Example: ExtractPageImage";

GdPicturePDF gdpicturePDFSrc = new GdPicturePDF();

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

{

    int pageCount = gdpicturePDFSrc.GetPageCount();

    GdPictureStatus status = gdpicturePDFSrc.GetStat();

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

    {

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

        int imageCount = gdpicturePDFSrc.GetPageImageCount();

        status = gdpicturePDFSrc.GetStat();

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

        {

            GdPicturePDF gdpicturePDFDest = new GdPicturePDF();

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

            {

                string message = "";

                int imageID = 0;

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

                {

                    imageID = gdpicturePDFSrc.ExtractPageImage(i);

                    status = gdpicturePDFSrc.GetStat();

                    if (status == GdPictureStatus.OK)

                    {

                        string res_name = gdpicturePDFDest.AddImageFromGdPictureImage(imageID, false, true);

                        status = gdpicturePDFSrc.GetStat();

                        if (status == GdPictureStatus.OK)

                            message = message + "The image nr. " + i.ToString() + " has been successfully drawn.\n";

                        else

                            message = message + "The AddImageFromGdPictureImage() method has failed for the image nr. " + i.ToString() + " with the status: " + status.ToString() + "\n";

                        if (GdPictureDocumentUtilities.DisposeImage(imageID) != GdPictureStatus.OK)

                            message = message + "The DisposeImage() method has failed for the image nr. " + i.ToString() + " with the status: " + status.ToString() + "\n";

                    }

                    else

                        message = message + "The ExtractPageImage() method has failed for the image nr. " + i.ToString() + " with the status: " + status.ToString() + "\n";

                }

                if (gdpicturePDFDest.SaveToFile("test_ExtractPageImage.pdf") == GdPictureStatus.OK)

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

                else

                    message = message + "The file can't be saved. Status: " + gdpicturePDFDest.GetStat().ToString();

                MessageBox.Show(message, caption);

            }

            else

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

            gdpicturePDFDest.Dispose();

        }

        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);

gdpicturePDFSrc.Dispose();
See Also