Annotations and signatures

Hello,

I would like to open an existing PDF-File which is digitally signed and add a text annotation. In this code, I am also adding a new signature, because I did not find a way to save the document without invalidating the existing signatures.

        static void Main(string[] args)
        {
            Aspose.Pdf.License license = new Aspose.Pdf.License();
            license.SetLicense("Aspose.Total.NET.lic");
            string inFile = System.IO.Path.Combine("c:\\temp", "input.pdf");
            string outFile = System.IO.Path.Combine("c:\\temp", "output.pdf");
            using (Document document = new Document(inFile))
            {

                Aspose.Pdf.Annotations.FreeTextAnnotation MyAnnotation = new Aspose.Pdf.Annotations.FreeTextAnnotation(document, new Aspose.Pdf.Annotations.DefaultAppearance());

                Aspose.Pdf.Annotations.Border border = new Aspose.Pdf.Annotations.Border(MyAnnotation);
                border.Width = 5;
                border.Dash = new Aspose.Pdf.Annotations.Dash(1, 1);

                MyAnnotation.Title = "Sample Annotation Title";
                MyAnnotation.Subject = "Sample Subject";
                MyAnnotation.Contents = "Testtext";
                MyAnnotation.Border = border;
                MyAnnotation.Color = Aspose.Pdf.Color.DarkGreen;
                MyAnnotation.RichText = "Testtext";
                MyAnnotation.Rect = new Aspose.Pdf.Rectangle(200, 400, 400, 600);

                document.Pages[1].Annotations.Add(MyAnnotation);

                using (PdfFileSignature signature = new PdfFileSignature(document))
                {
                    PKCS7 pkcs = new PKCS7(@"C:\temp\test.pfx", "test"); // Use PKCS7/PKCS7Detached objects
                    signature.Sign(1, true, new System.Drawing.Rectangle(300, 100, 400, 200), pkcs);
                    signature.Save(outFile);
                }
            }
        }

The first problem is that in the output.pdf the annotation is missing.

If I use document.Save(outFile); instead, it shows the annotation but the old signatures are invalid.

The annotations does not show any text, that’s the next problem.

Sorry, if I did not use all C#-conventions correctly.
Thanks for your help!

@HARIAT,

The signature makes the edition of a document not possible. That is why. The whole purpose of a signature is to validate the user and the content, so it makes no send to be able to edit it.

Could you please attach the test pdf document and test certificate so I can try to replicate this?

Hi Carlos,
thanks for your answer.

I do not want to change the document itself, I just want to add an annotation. And this is supportet behaviour in Acrobat Reader. I can add an annoation to a signed pdf and it does not invalidate the signature, it just shows a warning in the signature-windows stating that an annotation has been added.
input.pdf (78.6 KB) is the original signed file, output_acrobat.pdf (102.9 KB) is the file with the annotation.
And that is what I want to do with Aspose - I don’t really want to add a new signature. I would think, that the code for this should be somethin like

        static void Main(string[] args)
        {
            Aspose.Pdf.License license = new Aspose.Pdf.License();
            license.SetLicense("Aspose.Total.NET.lic");
            string inFile = System.IO.Path.Combine("c:\\temp", "input.pdf");
            string outFile = System.IO.Path.Combine("c:\\temp", "output_aspose.pdf");
            using (Document document = new Document(inFile))
            {

                Aspose.Pdf.Annotations.FreeTextAnnotation MyAnnotation = new Aspose.Pdf.Annotations.FreeTextAnnotation(document, new Aspose.Pdf.Annotations.DefaultAppearance());

                Aspose.Pdf.Annotations.Border border = new Aspose.Pdf.Annotations.Border(MyAnnotation);
                border.Width = 3;
                border.Style = 0;

                MyAnnotation.Contents = "Testtext";
                MyAnnotation.Border = border;
                MyAnnotation.Rect = new Aspose.Pdf.Rectangle(200, 400, 400, 600);
                MyAnnotation.Flags = 0;

                document.Pages[1].Annotations.Add(MyAnnotation);

                document.Save(outFile);
            }
        }

But even if I do not add the annotation the document.Save-part allready invalidates the signatures.
And additionally still the annotation is not correctly displayed. Only after changing any of its properties in Acrobat Reader it gets visible. You can see the result here: output_aspose.pdf (79.1 KB)

Best regards,
Harald

@HARIAT,

I see. Let me research this a bit more.

@HARIAT,

This seems like a bug, as is not behaving as Acrobat. I will create a ticket for the dedv team.

@HARIAT
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PDFNET-54540

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

Hi @carlos.molina,

thanks a lot for your answer and your good work!

Harald

@HARIAT,

Let us know if you need help with something else.