empira / PDFsharp-1.5

A .NET library for processing PDF
MIT License
1.28k stars 588 forks source link

AcroForm is always null #100

Open BergenSoft opened 5 years ago

BergenSoft commented 5 years ago

I want to create a pdf with fields in it. I use MigraDoc but my problem is related to pdfSharp classes.

        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: 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);

My problem is that the pdfRenderer.PdfDocument.AcroForm is always null and there is no possibility to create a new object. Unfortunately there is no example on the homepage.

AnthonyWillekens commented 4 years ago

i've exactly the same problem. Any issue since this post?

KC7465128305 commented 2 years ago

I have exactly the same problem. I have AcroForm equal to null and there is no help on the internet.

BergenSoft commented 2 years ago

I found a workaround for my problem. Maybe it helps also you. See here: https://stackoverflow.com/a/57670391/5772381

KC7465128305 commented 2 years ago

Thanks! Just what I need. I also found this https://stackoverflow.com/questions/54486608/c-create-pdf-form-acroform-using-pdfsharp

This one is adding a text field instead of a signature field.