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 As Integer, _
ByRef () As Byte _
) As GdPictureStatus
public GdPictureStatus ExtractEmbeddedFile(
int ,
ref byte[]
)
public function ExtractEmbeddedFile(
: Integer;
var : Bytearray of
): GdPictureStatus;
public function ExtractEmbeddedFile(
: int,
: byte[]
) : GdPictureStatus;
public: GdPictureStatus ExtractEmbeddedFile(
int ,
ref byte[]*
)
public:
GdPictureStatus ExtractEmbeddedFile(
int ,
array<byte>^%
)
Parameters
- FileIdx
- The 0-based index of the embedded file. It must be a value from 0 to GdPicturePDF.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.
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();
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