WIP: PDF Attachment Extractor
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports GdPicture14
|
||||
|
||||
Public Class Form1
|
||||
Private oSubform As Form3
|
||||
@@ -35,4 +36,44 @@ Public Class Form1
|
||||
MsgBox(ex.Message)
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
|
||||
Using oGdPicturePDF As GdPicturePDF = New GdPicturePDF()
|
||||
If oGdPicturePDF.LoadFromFile(TextBox1.Text, False) = GdPictureStatus.OK Then
|
||||
Dim embeddedFileCount As Integer = oGdPicturePDF.GetEmbeddedFileCount()
|
||||
If oGdPicturePDF.GetStat() = GdPictureStatus.OK Then
|
||||
If embeddedFileCount > 0 Then
|
||||
Dim FileName As String = oGdPicturePDF.GetEmbeddedFileName(0)
|
||||
If oGdPicturePDF.GetStat() = GdPictureStatus.OK Then
|
||||
Dim FileSize As Integer = oGdPicturePDF.GetEmbeddedFileSize(0)
|
||||
If oGdPicturePDF.GetStat() = GdPictureStatus.OK Then
|
||||
Dim FileData As Byte() = New Byte(FileSize) {}
|
||||
Dim status As GdPictureStatus = oGdPicturePDF.ExtractEmbeddedFile(0, FileData)
|
||||
If status = GdPictureStatus.OK Then
|
||||
MessageBox.Show("The content of the first embedded file has been extracted successfully.", "Example: Emdedded files (Attachments)", MessageBoxButtons.OK, MessageBoxIcon.Information)
|
||||
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 of the embedded file has been saved successfully.", "Example: Emdedded files (Attachments)", MessageBoxButtons.OK, MessageBoxIcon.Information)
|
||||
Else
|
||||
MessageBox.Show("The embedded file has failed to extract. Status: " + status.ToString(), "Example: Emdedded files (Attachments)", MessageBoxButtons.OK, MessageBoxIcon.Error)
|
||||
End If
|
||||
Else
|
||||
MessageBox.Show("An error occurred getting the file size. Status: " + oGdPicturePDF.GetStat().ToString(), "Example: Emdedded files (Attachments)", MessageBoxButtons.OK, MessageBoxIcon.Error)
|
||||
End If
|
||||
Else
|
||||
MessageBox.Show("An error occurred getting the file name. Status: " + oGdPicturePDF.GetStat().ToString(), "Example: Emdedded files (Attachments)", MessageBoxButtons.OK, MessageBoxIcon.Error)
|
||||
End If
|
||||
Else
|
||||
MessageBox.Show("This PDF file does not contain embedded files.", "Example: Emdedded files (Attachments)", MessageBoxButtons.OK, MessageBoxIcon.Information)
|
||||
End If
|
||||
Else
|
||||
MessageBox.Show("An error occurred getting the number of embedded files. Status: " + oGdPicturePDF.GetStat().ToString(), "Example: Emdedded files (Attachments)", MessageBoxButtons.OK, MessageBoxIcon.Error)
|
||||
End If
|
||||
Else
|
||||
MessageBox.Show("The file can't be loaded.", "Example: Emdedded files (Attachments)", MessageBoxButtons.OK, MessageBoxIcon.Error)
|
||||
End If
|
||||
End Using
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
Reference in New Issue
Block a user