I create a new PDF file using PDFsharp and MigraDoc. Now I want to add a field where the user can click on it and select a certificate for digital signing the file.
I found in the web, that this should be possible with AcroForms.
But I wasn't able to use AcroForm
because it is always null.
My current example code:
Document document = new Document();
Section section = document.AddSection();
section.AddParagraph("Signature Test");
PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(false, PdfFontEmbedding.Always);
pdfRenderer.Document = document;
pdfRenderer.RenderDocument();
// NullPointerException at the following line. AcroForm is null
pdfRenderer.PdfDocument.AcroForm.Elements.Add(PdfAcroForm.Keys.SigFlags, new PdfInteger(3));
const string filename = "HelloWorld.pdf";
pdfRenderer.PdfDocument.Save(filename);
Process.Start(filename);
Why is this property null? What can I do to set this to a correct value?
Or better, how can I add a field to select the digital certificate?