From 2b4afb0530fa879bae13bcf9ef13d5b2c192a187 Mon Sep 17 00:00:00 2001 From: Moti Date: Wed, 25 Sep 2019 10:26:17 +0300 Subject: [PATCH 1/2] Fixing bug of annotations as PdfReference I found a bug when added signature to existing pdf file annotations as it is of type PdfReference and not PdfArray. Calling to GetArray fixes the bug. --- src/PdfSharp/Pdf.Signatures/PdfSignatureHandler.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/PdfSharp/Pdf.Signatures/PdfSignatureHandler.cs b/src/PdfSharp/Pdf.Signatures/PdfSignatureHandler.cs index 1fd2844d..65e6557c 100644 --- a/src/PdfSharp/Pdf.Signatures/PdfSignatureHandler.cs +++ b/src/PdfSharp/Pdf.Signatures/PdfSignatureHandler.cs @@ -129,10 +129,16 @@ private void AddSignatureComponents(object sender, EventArgs e) this.contentsTraker = new PositionTracker(paddedContents); this.rangeTracker = new PositionTracker(paddedRange); - if (!Document.Pages[0].Elements.ContainsKey(PdfPage.Keys.Annots)) + var annotations = Document.Pages[0].Elements.GetArray(PdfPage.Keys.Annots); + if (annotations == null) + { Document.Pages[0].Elements.Add(PdfPage.Keys.Annots, new PdfArray(Document)); - - (Document.Pages[0].Elements[PdfPage.Keys.Annots] as PdfArray).Elements.Add(signature); + (Document.Pages[0].Elements[PdfPage.Keys.Annots] as PdfArray).Elements.Add(signature); + } + else + { + annotations.Elements.Add(signature); + } catalog.AcroForm.Fields.Elements.Add(signature); From 694fde9843f4aa7ae380a04bab6fd4d3801eb2ca Mon Sep 17 00:00:00 2001 From: Moti Date: Wed, 25 Sep 2019 13:41:57 +0300 Subject: [PATCH 2/2] moving signature to the array ctor --- src/PdfSharp/Pdf.Signatures/PdfSignatureHandler.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/PdfSharp/Pdf.Signatures/PdfSignatureHandler.cs b/src/PdfSharp/Pdf.Signatures/PdfSignatureHandler.cs index 65e6557c..f0e64c93 100644 --- a/src/PdfSharp/Pdf.Signatures/PdfSignatureHandler.cs +++ b/src/PdfSharp/Pdf.Signatures/PdfSignatureHandler.cs @@ -132,8 +132,7 @@ private void AddSignatureComponents(object sender, EventArgs e) var annotations = Document.Pages[0].Elements.GetArray(PdfPage.Keys.Annots); if (annotations == null) { - Document.Pages[0].Elements.Add(PdfPage.Keys.Annots, new PdfArray(Document)); - (Document.Pages[0].Elements[PdfPage.Keys.Annots] as PdfArray).Elements.Add(signature); + Document.Pages[0].Elements.Add(PdfPage.Keys.Annots, new PdfArray(Document, signature)); } else {