I tried to fill a acrofields in c# but for some reason, it wont work.
There is my code :
using iText.Layout; using iText.Forms; using iText.Kernel.Pdf; using iText.Forms.Fields; fileNameExisting = @"Facturation.pdf"; fileNameNew = @"newfacturation.pdf"; public class Pdfinterne { public static void Fillfact(string fileNameExisting, string fileNameNew) { PdfDocument pdfDoc = new iText.Kernel.Pdf.PdfDocument(new PdfReader(fileNameExisting), new PdfWriter(fileNameNew)); PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true); form.GetField("Contrat").SetValue("12345", "12345"); pdfDoc.Close(); }
The error is at the PdfAcroForm line.
"System.NullReferenceException: 'Object reference not set to an instance of an object.'"
I just dont get it. I tried with itextsharp (pdfstamper) but read that it was fixed with Itext7 so i moove to Itext7 but exacly same problem.
The Facutration.pdf file is working fine and all the acrofields can be fill.
Any one get an hint on this ?
Thanks
Edit : Modify code