From b995304ee33f43afad448f45dded9860caeb56c7 Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Wed, 4 Mar 2020 14:44:18 +0100 Subject: [PATCH] WIP: PDF Attachment Extractor --- .../Form1.Designer.vb | 12 ++++++ GUIs.Test.DocumentViewerTest/Form1.vb | 41 +++++++++++++++++++ Modules.Jobs/EDMI/ZUGFeRD/PDFAttachments.vb | 9 ++++ Modules.Jobs/Jobs.vbproj | 1 + 4 files changed, 63 insertions(+) create mode 100644 Modules.Jobs/EDMI/ZUGFeRD/PDFAttachments.vb diff --git a/GUIs.Test.DocumentViewerTest/Form1.Designer.vb b/GUIs.Test.DocumentViewerTest/Form1.Designer.vb index c83cf8f2..b1a5abd3 100644 --- a/GUIs.Test.DocumentViewerTest/Form1.Designer.vb +++ b/GUIs.Test.DocumentViewerTest/Form1.Designer.vb @@ -27,6 +27,7 @@ Partial Class Form1 Me.Button1 = New System.Windows.Forms.Button() Me.Button2 = New System.Windows.Forms.Button() Me.Button3 = New System.Windows.Forms.Button() + Me.Button4 = New System.Windows.Forms.Button() Me.SuspendLayout() ' 'TextBox1 @@ -67,11 +68,21 @@ Partial Class Form1 Me.Button3.Text = "Load Form4" Me.Button3.UseVisualStyleBackColor = True ' + 'Button4 + ' + Me.Button4.Location = New System.Drawing.Point(12, 96) + Me.Button4.Name = "Button4" + Me.Button4.Size = New System.Drawing.Size(637, 23) + Me.Button4.TabIndex = 3 + Me.Button4.Text = "Extract Files from PDF" + Me.Button4.UseVisualStyleBackColor = True + ' 'Form1 ' Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font Me.ClientSize = New System.Drawing.Size(800, 450) + Me.Controls.Add(Me.Button4) Me.Controls.Add(Me.Button3) Me.Controls.Add(Me.Button2) Me.Controls.Add(Me.Button1) @@ -87,4 +98,5 @@ Partial Class Form1 Friend WithEvents Button1 As Button Friend WithEvents Button2 As Button Friend WithEvents Button3 As Button + Friend WithEvents Button4 As Button End Class diff --git a/GUIs.Test.DocumentViewerTest/Form1.vb b/GUIs.Test.DocumentViewerTest/Form1.vb index 33cc0654..0aaf2df7 100644 --- a/GUIs.Test.DocumentViewerTest/Form1.vb +++ b/GUIs.Test.DocumentViewerTest/Form1.vb @@ -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 diff --git a/Modules.Jobs/EDMI/ZUGFeRD/PDFAttachments.vb b/Modules.Jobs/EDMI/ZUGFeRD/PDFAttachments.vb new file mode 100644 index 00000000..78708998 --- /dev/null +++ b/Modules.Jobs/EDMI/ZUGFeRD/PDFAttachments.vb @@ -0,0 +1,9 @@ +Public Class PDFAttachments + Public Sub New(GdPictureKey As String) + + End Sub + + Public Shared Function Extract(FileName As String) + Using oGDPicturePDF As New GDPicturePDF + End Function +End Class diff --git a/Modules.Jobs/Jobs.vbproj b/Modules.Jobs/Jobs.vbproj index 59c4bb25..8258ced9 100644 --- a/Modules.Jobs/Jobs.vbproj +++ b/Modules.Jobs/Jobs.vbproj @@ -88,6 +88,7 @@ +