diff --git a/src/PdfSharp/Pdf.Signatures/PdfSignatureHandler.cs b/src/PdfSharp/Pdf.Signatures/PdfSignatureHandler.cs index 1fd2844d..f0e64c93 100644 --- a/src/PdfSharp/Pdf.Signatures/PdfSignatureHandler.cs +++ b/src/PdfSharp/Pdf.Signatures/PdfSignatureHandler.cs @@ -129,10 +129,15 @@ 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)) - Document.Pages[0].Elements.Add(PdfPage.Keys.Annots, new PdfArray(Document)); - - (Document.Pages[0].Elements[PdfPage.Keys.Annots] as PdfArray).Elements.Add(signature); + var annotations = Document.Pages[0].Elements.GetArray(PdfPage.Keys.Annots); + if (annotations == null) + { + Document.Pages[0].Elements.Add(PdfPage.Keys.Annots, new PdfArray(Document, signature)); + } + else + { + annotations.Elements.Add(signature); + } catalog.AcroForm.Fields.Elements.Add(signature);