0

In my .Net project, I am using

    <PackageReference Include="itext7" Version="7.2.0" />

In c# class,

PdfAcroForm form = PdfAcroForm.GetAcroForm(pdf, true);

PdfTextFormField borrowerField = PdfFormField.CreateText(pdf);

borrowerField.SetFieldName("Borrowers_Name");
borrowerField.SetValue("Name");
form.AddField(borrowerField);

I can see field name as "Borrowers_Name" but value is iText.Forms.Fields.PdfTextFormField instead of Name. Hence in my PDF, I see value as blank.

When I try to get value using

form.GetField("Borrowers_Name").GetValueAsString();

I can see value which is set. But when I open up the pdf, it's empty.

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
user14463446
  • 99
  • 10
  • The following may be helpful: https://stackoverflow.com/questions/68941615/is-itext7-available-in-vb-net-or-only-c-sharp/68946796#68946796 (it's in VB.NET, but should be easy to convert) – Tu deschizi eu inchid Feb 17 '22 at 23:57

1 Answers1

1

You create a form field but you don't define its area on page. Thus, the field is created as invisible field.

The easiest way to define an on-page area for your field is in the creation method, e.g. by replacing

PdfTextFormField borrowerField = PdfFormField.CreateText(pdf);

by

PdfTextFormField borrowerField = PdfFormField.CreateText(pdf, new Rectangle(100, 600, 200, 20));

With this you get a visual representation of your field like this:

Screen shot of field

mkl
  • 90,588
  • 15
  • 125
  • 265