Skip to main content
Skip table of contents

How to add a hidden text field?


I'd like to create a text field with iTextSharp that is not visible.


Here's code I'm using to create a text field:


TextField field = new TextField(writer, new Rectangle(x, y - h, x + w, y), name);
field.BackgroundColor = new BaseColor(bgcolor[0], bgcolor[1], bgcolor[2]);
field.BorderColor = new BaseColor(
    bordercolor[0], bordercolor[1], bordercolor[2]);
field.BorderWidth = border;
field.BorderStyle = PdfBorderDictionary.STYLE_SOLID;
field.Text = text;
writer.AddAnnotation(field.GetTextField());


Posted on StackOverflow on May 21, 2013 

In Java, using iText 7 you should initialize a text field via the PdfTextFormField class. It has a method named setVisibility() with the following values:

  • PdfFormField.HIDDEN,
  • PdfFormField.VISIBLE_BUT_DOES_NOT_PRINT, and
  • PdfFormField.HIDDEN_BUT_PRINTABLE.

So you’ll just apply this method: field.setVisibility(PdfFormField.HIDDEN);

As you're using iTextSharp, you should look for the Visibility property.

field.Visibility = PdfFormField.HIDDEN;

Click How to add a hidden text field? if you want to see how to answer this question in iText 5.


JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.