Add MessageId to Embedded Attachments
This commit is contained in:
@@ -5,17 +5,20 @@ Imports GdPicture14
|
||||
|
||||
Public Class PDFAttachments
|
||||
Private Logger As Logger
|
||||
Private Filesystem As Filesystem.File
|
||||
|
||||
Private Const ZUGFERD_XML_FILENAME = "ZUGFeRD-invoice.xml"
|
||||
|
||||
Public Class AttachmentResult
|
||||
Public FileName As String
|
||||
Public FileContents As Byte()
|
||||
End Class
|
||||
|
||||
Public Sub New(LogConfig As LogConfig, GdPictureKey As String)
|
||||
Logger = LogConfig.GetLogger
|
||||
Filesystem = New Filesystem.File(LogConfig)
|
||||
End Sub
|
||||
|
||||
Public Function Extract(FileName As String, AllowedExtensions As List(Of String)) As List(Of FileInfo)
|
||||
Dim oResults As New List(Of FileInfo)
|
||||
Public Function Extract(FileName As String, AllowedExtensions As List(Of String)) As List(Of AttachmentResult)
|
||||
Dim oResults As New List(Of AttachmentResult)
|
||||
Dim oExtensions = AllowedExtensions.ConvertAll(Of String)(New Converter(Of String, String)(Function(ext) ext.ToUpper))
|
||||
|
||||
Try
|
||||
@@ -34,21 +37,31 @@ Public Class PDFAttachments
|
||||
Dim FileSize As Integer = oGDPicturePDF.GetEmbeddedFileSize(index)
|
||||
|
||||
If oGDPicturePDF.GetStat() = GdPictureStatus.OK Then
|
||||
Dim FileData As Byte() = New Byte(FileSize) {}
|
||||
Dim status As GdPictureStatus = oGDPicturePDF.ExtractEmbeddedFile(index, FileData)
|
||||
Dim oFileData As Byte() = New Byte(FileSize) {}
|
||||
Dim status As GdPictureStatus = oGDPicturePDF.ExtractEmbeddedFile(index, oFileData)
|
||||
|
||||
If status = GdPictureStatus.OK Then
|
||||
Dim oVersionedName = Filesystem.GetVersionedFilename(oFileName)
|
||||
Dim oTempName As String = Path.Combine(Path.GetTempPath(), oVersionedName)
|
||||
Using oFileStream As New FileStream(oTempName, FileMode.OpenOrCreate)
|
||||
oFileStream.Write(FileData, 0, FileData.Length)
|
||||
End Using
|
||||
|
||||
oResults.Add(New FileInfo(oTempName))
|
||||
oResults.Add(New AttachmentResult() With {
|
||||
.FileContents = oFileData,
|
||||
.FileName = oFileName
|
||||
})
|
||||
Else
|
||||
Logger.Error("The embedded file [{0}] has failed to extract. Status: {1}", oFileName, oGDPicturePDF.GetStat().ToString())
|
||||
Continue For
|
||||
End If
|
||||
|
||||
'If status = GdPictureStatus.OK Then
|
||||
' Dim oVersionedName = Filesystem.GetVersionedFilename(oFileName)
|
||||
' Dim oTempName As String = Path.Combine(Path.GetTempPath(), oVersionedName)
|
||||
' Using oFileStream As New FileStream(oTempName, FileMode.OpenOrCreate)
|
||||
' oFileStream.Write(oFileData, 0, oFileData.Length)
|
||||
' End Using
|
||||
|
||||
' oResults.Add(New FileInfo(oTempName))
|
||||
'Else
|
||||
' Logger.Error("The embedded file [{0}] has failed to extract. Status: {1}", oFileName, oGDPicturePDF.GetStat().ToString())
|
||||
' Continue For
|
||||
'End If
|
||||
Else
|
||||
Logger.Error("An error occurred getting the file size for [{0}]. Status: {1}", oFileName, oGDPicturePDF.GetStat().ToString())
|
||||
Continue For
|
||||
|
||||
Reference in New Issue
Block a user