GdPicture.NET.14
GdPicture14 Namespace / GdPicturePDF Class / ExtractEmbeddedFile Method
The 0-based index of the embedded file. It must be a value from 0 to GetEmbeddedFileCount-1.
Output parameter. An array of bytes containing the uncompressed content (data) of the embedded file.
Example





In This Topic
ExtractEmbeddedFile Method (GdPicturePDF)
In This Topic
Gets the uncompressed content of an embedded file (the content of an attached file) within the currently loaded PDF document, in bytes. You need to specify this attachment by its 0-based index.
Syntax
'Declaration
 
Public Function ExtractEmbeddedFile( _
   ByVal FileIdx As Integer, _
   ByRef Data() As Byte _
) As GdPictureStatus
public GdPictureStatus ExtractEmbeddedFile( 
   int FileIdx,
   ref byte[] Data
)
public function ExtractEmbeddedFile( 
    FileIdx: Integer;
   var  Data: Bytearray of
): GdPictureStatus; 
public function ExtractEmbeddedFile( 
   FileIdx : int,
   Data : byte[]
) : GdPictureStatus;
public: GdPictureStatus ExtractEmbeddedFile( 
   int FileIdx,
   ref byte[]* Data
) 
public:
GdPictureStatus ExtractEmbeddedFile( 
   int FileIdx,
   array<byte>^% Data
) 

Parameters

FileIdx
The 0-based index of the embedded file. It must be a value from 0 to GetEmbeddedFileCount-1.
Data
Output parameter. An array of bytes containing the uncompressed content (data) of the embedded file.

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 extract and save the content of the first embedded file within the PDF document.
Dim caption As String = "Example: ExtractEmbeddedFile"
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 FileName As String = gdpicturePDF.GetEmbeddedFileName(0)
            If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
                Dim FileSize As Integer = gdpicturePDF.GetEmbeddedFileSize(0)
                If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
                    Dim FileData As Byte() = New Byte(FileSize) {}
                    Dim status As GdPictureStatus = gdpicturePDF.ExtractEmbeddedFile(0, FileData)
                    If status = GdPictureStatus.OK Then
                        MessageBox.Show("The content of the first embedded file has been extracted successfully.", caption)
                        Dim oFileStream As System.IO.FileStream = Nothing
                        oFileStream = New System.IO.FileStream(FileName + "_content.dat", System.IO.FileMode.Create)
                        oFileStream.Write(FileData, 0, FileData.Length)
                        oFileStream.Close()
                        MessageBox.Show("The content has been saved successfully.", caption)
                    Else
                        MessageBox.Show("The ExtractEmbeddedFile() method has failed with the status: " + status.ToString(), caption)
                    End If
                End If
            End If
        End If
    End If
Else
    MessageBox.Show("The file can't be loaded.", caption)
End If
gdpicturePDF.Dispose()
string caption = "Example: ExtractEmbeddedFile";
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
        {
            string FileName = gdpicturePDF.GetEmbeddedFileName(0);
            if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
            {
                int FileSize = gdpicturePDF.GetEmbeddedFileSize(0);
                if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
                {
                    byte[] FileData = new byte[FileSize + 1];
                    GdPictureStatus status = gdpicturePDF.ExtractEmbeddedFile(0, ref FileData);
                    if (status == GdPictureStatus.OK)
                    {
                        MessageBox.Show("The content of the first embedded file has been extracted successfully.", caption);
                        System.IO.FileStream oFileStream = default(System.IO.FileStream);
                        oFileStream = new System.IO.FileStream(FileName + "_content.dat", System.IO.FileMode.Create);
                        oFileStream.Write(FileData, 0, FileData.Length);
                        oFileStream.Close();
                        MessageBox.Show("The content has been saved successfully.", caption);
                    }
                    else
                    {
                        MessageBox.Show("The ExtractEmbeddedFile() method has failed with the status: " + status.ToString(), caption);
                    }
               }
           }
        }
    }
}
else
{
    MessageBox.Show("The file can't be loaded.", caption);
}
gdpicturePDF.Dispose();
See Also