2

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)
(...)
Damian K.
  • 29
  • 4
  • *"but this line throws an exception"* - can you also share its stack trace? – mkl Nov 10 '17 at 16:30
  • I don't think your question is a duplicate of the generic "What is a NullReferenceException" question. But unless you provide a [sscce](http://sscce.org/), I don't think you'll get a specific answer. – mkl Nov 13 '17 at 15:46
  • I thought I told everything. What else would be helpful? – Damian K. Nov 14 '17 at 07:43
  • It turned out it was an iText7 bug, fixed in 7.0.5. version. – Damian K. Nov 14 '17 at 09:09

0 Answers0