Merge and Sign PDF files digitally in C# using Aspose.PDF for .NET - Signature becomes invalid

Hello,

We have been using Aspose.PDF to merge PDF files. We have found that multiple signature invalid for merged PDF files.

We have the following flow:

Merge two PDF/A-1B files
Sign result file with first signature
Sign result file with second signature

And after step 3, the first signature (applied on the 2td step) become invalid.

NOTE 1: we use external tool to sign PDF/A file, however when we try to sign with Aspose, we still have this problem.
NOTE 2: It seems that problem not in signature, but in the created PDF/A-1B file. If converted file is opened and re-saved with Adobe - signing works correct.
NOTE 3: we are using Aspose.Pdf v19.11 and Aspose.Words v19.11
NOTE 4: perhabs similar to this issue (PDFNET-47442)

Code example:

using System.Collections.Generic;
using System.IO;
using Aspose.Pdf;
using Aspose.Pdf.Facades;

namespace TestMergeAsposeAndDoubleSigning
{
    class Program
    {
        private static string PfxFileName = @"D:\pdfAIssue\cert.pfx";
        private static string CertificatePassword = "1q2w3e4r5t";

        static void Main()
        {
            var files = new List<string>();
            files.Add("pdfa1.pdf");
            files.Add("pdfa2.pdf");

            var mergedFileName = "merged.pdf";
            var firstSign = "firstSign.pdf";
            var result = "result.pdf";
            Merge(files, mergedFileName);

            Sign(mergedFileName, firstSign);
            Sign(firstSign, result);
        }
        
        private static void Merge(
            List<string> filesPath,
            string outputFilePath)
        {
            var license = new License();
            license.SetLicense("Aspose.Total.lic");

            Document outputDocument = null;

            foreach (var filePath in filesPath)
            {
                if (outputDocument == null)
                {
                    outputDocument = new Document();
                }

                var inputDocument = new Document(filePath);

                outputDocument.Pages.Add(inputDocument.Pages);
            }

            outputDocument.Convert(
                new MemoryStream(),
                PdfFormat.PDF_A_1B,
                ConvertErrorAction.None /*GetErrorAction(parameters)*/);

            outputDocument.Save(outputFilePath);
        }

        private static void Sign(string inputFilePath, string outputFilePath)
        {
            var license = new License();
            license.SetLicense("Aspose.Total.lic");

            using (PdfFileSignature pdfSign = new PdfFileSignature())
            {
                pdfSign.BindPdf(inputFilePath);
                pdfSign.SetCertificate(PfxFileName, CertificatePassword);
                pdfSign.Sign(1, "Signature Reason", "Contact", "Location", false, System.Drawing.Rectangle.Empty);
                pdfSign.Save(outputFilePath);
            }
        }
    }
}

Files:
pdfaSigningIssue.zip (1.4 MB)

@uaprogrammer,

Can you please share source files along with generated result and environment details so that we may further investigate to help you out.

Hello,

I have added files.
Enviroment: windows 10, x64

Thanks

@uaprogrammer,

Thanks for contacting support.

I have observed your issue and like to inform that I have created ticket with ID PDFNET-47666 in our issue tracking system to investigate and resolve this issue as soon possible.

Hi, we recently updated our Aspose libraries to version 20.12.0. We are merging documents using the exact same method above that were signed by DocuSign. The signatures are being invalidated on the documents due to the merge. Is there an ETA on when ticket PDFNET-47666 will be resolved?

@joel.brewster.impact

We are afraid that earlier logged ticket is not yet resolved due to other issue logged prior to it. However, we will surely inform you as soon as it is completely investigated and any news about its ETA is available. Please give us some time.

We apologize for the inconvenience.

The issues you have found earlier (filed as PDFNET-47666) have been fixed in Aspose.PDF for .NET 21.9.