Reputation: 8098
I have the following code:
PdfStamper pst = null;
try
{
PdfReader reader = new PdfReader(GetTemplateBytes());
pst = new PdfStamper(reader, Response.OutputStream);
var acroFields = pst.AcroFields;
pst.FormFlattening = true;
pst.FreeTextFlattening = true;
pst.SetFullCompression();
SetFieldsInternal(acroFields);
pst.Close();
}
protected override void SetFieldsInternal(iTextSharp.text.pdf.AcroFields acroFields)
{
acroFields.SetFieldProperty("txtForOffer", "setflags", PdfAnnotation.FLAGS_PRINT, null);
}
How do I show / hide the acrofields in the SetFieldsInternal function ?
The point is that the user may want to download 2 versions of the PDF, one with some text showing, one without text showing.
The template PDF is generated using OpenOffice. I just fill in the acrofields.
Upvotes: 1
Views: 7174
Reputation: 10463
You can set an AcroField as readonly like this:
form.setFieldProperty("companyFld", "setfflags", PdfFormField.FF_READ_ONLY, null);
It is "setfflags" BTW not "setflags"
EDIT: MY BAD!!! You asked to make a field visible or not. You would use the "setflags" argument in this case and you can pass any of the PdfAnnotation FLAGS_ constants to adjust visibility.
Upvotes: 2