GdPicture.NET.14
GdPicture14 Namespace / GdPicturePDF Class / DeleteEmbeddedFile Method
The 0-based index of the embedded file you want to remove. It must be a value from 0 to GetEmbeddedFileCount-1.
Example





In This Topic
DeleteEmbeddedFile Method (GdPicturePDF)
In This Topic
Removes an embedded (attached) file from your currently loaded PDF document. You need to specify this attachment by its 0-based index.
Syntax
'Declaration
 
Public Function DeleteEmbeddedFile( _
   ByVal FileIdx As Integer _
) As GdPictureStatus
public GdPictureStatus DeleteEmbeddedFile( 
   int FileIdx
)
public function DeleteEmbeddedFile( 
    FileIdx: Integer
): GdPictureStatus; 
public function DeleteEmbeddedFile( 
   FileIdx : int
) : GdPictureStatus;
public: GdPictureStatus DeleteEmbeddedFile( 
   int FileIdx
) 
public:
GdPictureStatus DeleteEmbeddedFile( 
   int FileIdx
) 

Parameters

FileIdx
The 0-based index of the embedded file you want to remove. It must be a value from 0 to GetEmbeddedFileCount-1.

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 remove the first embedded file from the PDF document.
Dim caption As String = "Example: DeleteEmbeddedFile"
Dim gdpicturePDF As New GdPicturePDF()
If gdpicturePDF.LoadFromFile("TestPDFWithAttachment.pdf", False) = GdPictureStatus.OK Then
    Dim embeddedFileCount As Integer = gdpicturePDF.GetEmbeddedFileCount()
    If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
        If embeddedFileCount = 0 Then
            MessageBox.Show("This PDF file does not contain embedded files.", caption)
        Else
            Dim status As GdPictureStatus = gdpicturePDF.DeleteEmbeddedFile(0)
            If status = GdPictureStatus.OK Then
                MessageBox.Show("The attachment has been successfully removed.", caption)
                If gdpicturePDF.SaveToFile("test_DeleteEmbeddedFile_func.pdf", False) <> GdPictureStatus.OK Then
                    MessageBox.Show("The file can't be saved.", caption)
                End If
            Else
                MessageBox.Show("The DeleteEmbeddedFile() method has failed with the status: " + status.ToString(), caption)
            End If
        End If
    End If
Else
    MessageBox.Show("The file can't be loaded.", caption)
End If
gdpicturePDF.Dispose()
string caption = "Example: DeleteEmbeddedFile";
GdPicturePDF gdpicturePDF = new GdPicturePDF();
if (gdpicturePDF.LoadFromFile("TestPDFWithAttachment.pdf", false) == GdPictureStatus.OK)
{
    int embeddedFileCount = gdpicturePDF.GetEmbeddedFileCount();
    if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
    {
        if (embeddedFileCount == 0)
        {
            MessageBox.Show("This PDF file does not contain embedded files.", caption);
        }
        else
        {
            GdPictureStatus status = gdpicturePDF.DeleteEmbeddedFile(0);
            if (status == GdPictureStatus.OK)
            {
                MessageBox.Show("The attachment has been successfully removed.", caption);
                if (gdpicturePDF.SaveToFile("test_DeleteEmbeddedFile_func.pdf", false) != GdPictureStatus.OK)
                {
                    MessageBox.Show("The file can't be saved.", caption);
                }
            }
            else
            {
                MessageBox.Show("The DeleteEmbeddedFile() method has failed with the status: " + status.ToString(), caption);
            }
        }
    }
}
else
{
    MessageBox.Show("The file can't be loaded.", caption);
}
gdpicturePDF.Dispose();
See Also