问题
I'd like to create a text field with iTextSharp that is not visible. Here's code I'm using to create a textfield:
TextField field = new iTextSharp.text.pdf.TextField(writer, new iTextSharp.text.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());
回答1:
In Java, the TextField
class has a method named setVisibility() inherited from its parent, the BaseField
class. Possible values are:
BaseField.VISIBLE
,BaseField.HIDDEN
,BaseField.VISIBLE_BUT_DOES_NOT_PRINT
, andBaseField.HIDDEN_BUT_PRINTABLE
.
As you're using iTextSharp, you should look for a SetVisibility()
method or a Visibility
property.
Using a render mode as suggested by another person in answer to this question applies to content written to a content stream, XObject or appearance. You are asking to hide a field, and that's something completely different.
回答2:
You could use TEXT_RENDER_MODE_INVISIBLE
but Ctrl+A will still select it - you have been warned!
来源:https://stackoverflow.com/questions/16665562/how-do-i-make-text-field-to-be-hidden