diff --git a/EnvelopeGenerator.Common/Jobs/FinalizeDocument/FinalizeDocumentJob.vb b/EnvelopeGenerator.Common/Jobs/FinalizeDocument/FinalizeDocumentJob.vb index 29e5328e..5862440f 100644 --- a/EnvelopeGenerator.Common/Jobs/FinalizeDocument/FinalizeDocumentJob.vb +++ b/EnvelopeGenerator.Common/Jobs/FinalizeDocument/FinalizeDocumentJob.vb @@ -160,26 +160,36 @@ Namespace Jobs Using oFinalStream As New MemoryStream() Using oDocumentPDF As New GdPicturePDF() Using oReportPDF As New GdPicturePDF() + Dim oStatus As GdPictureStatus = GdPictureStatus.OK ' Load the source file into memory oDocumentPDF.LoadFromStream(oDocumentStream, True) - If oDocumentPDF.GetStat() Then - Throw New MergeDocumentException($"Document could not be loaded: {oDocumentPDF.GetStat}") + + oStatus = oDocumentPDF.GetStat() + If oStatus <> GdPictureStatus.OK Then + Throw New MergeDocumentException($"Document could not be loaded: {oStatus}") End If ' Load the report file into memory oReportPDF.LoadFromStream(oReportStream, True) - If oDocumentPDF.GetStat() Then - Throw New MergeDocumentException($"Report could not be loaded: {oDocumentPDF.GetStat}") + oStatus = oReportPDF.GetStat() + If oStatus <> GdPictureStatus.OK Then + Throw New MergeDocumentException($"Report could not be loaded: {oStatus}") End If ' Merge the documents Dim oMergedPDF = oDocumentPDF.Merge2Documents(oDocumentPDF, oReportPDF) - If oDocumentPDF.GetStat() Then - Throw New MergeDocumentException($"Documents could not be merged: {oDocumentPDF.GetStat}") + oStatus = oMergedPDF.GetStat() + If oStatus <> GdPictureStatus.OK Then + Throw New MergeDocumentException($"Documents could not be merged: {oStatus}") End If - oMergedPDF.SaveToStream(oFinalStream) + ' Convert to PDF/A + oMergedPDF.ConvertToPDFA(oFinalStream, PdfConversionConformance.PDF_A_1b, True, True) + oStatus = oDocumentPDF.GetStat() + If oStatus <> GdPictureStatus.OK Then + Throw New MergeDocumentException($"Document could not be converted to PDF/A: {oStatus}") + End If Return oFinalStream.ToArray() End Using