I have a weird problem with iText7 when adding PdfTextMarkupAnnotation. The annotation itself works fine, but after that I want to insert a text form field and this where I am getting null reference exception. I realized it only occurs when adding text form field - other form fields also work fine. Here's some sample code:
private void InsertAnnotation(PdfPage page)
{
Rectangle rect = new Rectangle(10, 10, 100, 100);
float[] rectPoints = GetRectanglePoints();
PdfAnnotation annot = PdfTextMarkupAnnotation.CreateHighLight(rect, rectPoints);
page.AddAnnotation(annot);
}
and after that goes the text form field:
private void InsertTextBox(PdfPage page)
{
Rectangle rect = new Rectangle(50, 50, 50, 50);
PdfTextFormField txtField = PdfTextFormField.CreateText(pdfdocument, rect, "some name", "some default value");
m_AcroForm.AddField(txtField, page);
}
I've checked in the debugger and every parameter in CreateText()
seems to be fine, but this line throws an exception, so I dont really know what the problem is. It's also worth mentioning that when I'm trying to add only text form it works correctly, so the issue occurs when both functions work one after another. Any help would be appreciated ;)
Stack trace:
w iText.Kernel.Pdf.Annot.PdfAnnotation.GetPage()
w iText.Forms.Fields.PdfFormField.RegenerateField()
w iText.Forms.Fields.PdfFormField.SetValue(String value, Boolean generateAppearance)
w iText.Forms.Fields.PdfFormField.SetValue(String value)
w iText.Forms.Fields.PdfFormField.CreateText(PdfDocument doc, Rectangle rect, String name, String value, PdfFont font, Single fontSize, Boolean multiline)
w iText.Forms.Fields.PdfFormField.CreateText(PdfDocument doc, Rectangle rect, String name, String value)
w <class name>.InsertTextBox(PdfPage nPage)
(...)