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