GdPicture.NET.14.API
GdPicture14 Namespace / GdPicturePDF Class / DeleteImage Method
The image resource name previously returned by the AddImageFrom...(), AddJpegImageFrom...() or GdPicturePDF.GetPageImageResName methods.
Example





In This Topic
DeleteImage Method (GdPicturePDF)
In This Topic
Deletes a specified image and its corresponding image resource from the currently loaded PDF document. The required image is identified by its resource name within the current document. If the specified image is used either elsewhere on the same page or on another page, it is removed from all places within the current document.
Syntax
'Declaration
 
Public Function DeleteImage( _
   ByVal ImageResName As String _
) As GdPictureStatus
public GdPictureStatus DeleteImage( 
   string ImageResName
)
public function DeleteImage( 
    ImageResName: String
): GdPictureStatus; 
public function DeleteImage( 
   ImageResName : String
) : GdPictureStatus;
public: GdPictureStatus DeleteImage( 
   string* ImageResName
) 
public:
GdPictureStatus DeleteImage( 
   String^ ImageResName
) 

Parameters

ImageResName
The image resource name previously returned by the AddImageFrom...(), AddJpegImageFrom...() or GdPicturePDF.GetPageImageResName methods.

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.
Example
How to successfully delete all image resources included within the first page of a PDF document.
Dim caption As String = "Example: DeleteImage"
Dim gdpicturePDF As New GdPicturePDF()
If gdpicturePDF.LoadFromFile("deleteimage.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 = "", imageResName As String = ""
            For i As Integer = imageCount - 1 To 0 Step -1
            'The inverse loop will not work correctly from logical point of view (the number of images decreases).
                imageResName = gdpicturePDF.GetPageImageResName(i)
                status = gdpicturePDF.GetStat()
                If status = GdPictureStatus.OK Then
                    status = gdpicturePDF.DeleteImage(imageResName)
                    If status = GdPictureStatus.OK Then
                        message = message + "The image resource named " + imageResName + " has been successfully deleted." + vbCrLf
                    Else
                        message = message + "The DeleteImage() method has failed for the image resource named " + imageResName + " with the status: " + status.ToString() + vbCrLf
                    End If
                Else
                    message = message + "The GetPageImageResName() method has failed for the image indexed as " + i.ToString() + " with the status: " + status.ToString() + vbCrLf
                End If
            Next
            If gdpicturePDF.SaveToFile("test_deleteimage.pdf") = GdPictureStatus.OK Then
                message = message + "The file has been saved successfully."
            Else
                message = message + "The file can't be saved. Status: " + gdpicturePDF.GetStat().ToString()
            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: DeleteImage";
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 = "", imageResName = "";
            for (int i = imageCount - 1; i >= 0; i--)
            //The inverse loop will not work correctly from logical point of view (the number of images decreases).
            {
                imageResName = gdpicturePDF.GetPageImageResName(i);
                status = gdpicturePDF.GetStat();
                if (status == GdPictureStatus.OK)
                {
                    status = gdpicturePDF.DeleteImage(imageResName);
                    if (status == GdPictureStatus.OK)
                        message = message + "The image resource named " + imageResName + " has been successfully deleted.\n";
                    else
                        message = message + "The DeleteImage() method has failed for the image resource named " + imageResName + " with the status: " + status.ToString() + "\n";
                }
                else
                    message = message + "The GetPageImageResName() method has failed for the image indexed as " + i.ToString() + " with the status: " + status.ToString() + "\n";
            }
            if (gdpicturePDF.SaveToFile("test_DeleteImage.pdf") == GdPictureStatus.OK)
                message = message + "The file has been saved successfully.";
            else
                message = message + "The file can't be saved. Status: " + gdpicturePDF.GetStat().ToString();
            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