在 iTextSharp 中显示/隐藏 AcroField
我有以下代码:
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);
}
如何在 SetFieldsInternal 函数中显示/隐藏 acrofields ?
关键是用户可能想要下载 2 个版本的 PDF,一个显示一些文本,一个不显示文本。
模板 PDF 是使用 OpenOffice 生成的。我只是填写 acrofields。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将 AcroField 设置为只读,如下所示:
它是“setfflags”顺便说一句,而不是“setflags”
编辑:我的错!您要求使字段可见或不可见。在这种情况下,您将使用“setflags”参数,并且可以传递任何 PdfAnnotation FLAGS_ 常量来调整可见性。
You can set an AcroField as readonly like this:
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.