我使用iTextSharp创建了一个组合框,但该组合框在打印时不可见。我已经试着设置了旗帜,但都没有用。
foreach (XElement choices in xElement.Elements())
{
optionList.Add(choices.Attribute("displayName").Value);
}
string[] optionArray = optionList.ToArray();
PdfFormField combo = PdfFormField.CreateCombo(writer, true, optionArray,0);
combo.SetWidget(new Rectangle(sectionX +10+ textLength + 2, fieldIncrementer-3,
sectionX + Convert.ToSingle(xElement.Parent.Attribute("width").Value),
fieldIncrementer + FontSize-3), PdfName.HIGHLIGHT);
combo.FieldName = xElement.Attribute("name").Value;
combo.SetFieldFlags(PdfAnnotation.FLAGS_PRINT);
writer.AddAnnotation(combo);发布于 2014-07-16 02:51:42
我用一种不同的方式解决了这个问题。下面是我更新后的代码:
foreach (XElement choices in xElement.Elements())
{
optionList.Add(choices.Attribute("displayName").Value);
}
string[] optionArray = optionList.ToArray();
var _text = new TextField(writer,
new Rectangle(sectionX + 10 + textLength + 2, fieldIncrementer - 3,
sectionX + Convert.ToSingle(xElement.Parent.Attribute("width").Value),
fieldIncrementer + FontSize - 3), xElement.Attribute("name").Value.Trim());
_text.Choices = optionArray;
writer.AddAnnotation(_text.GetComboField());发布于 2014-07-16 15:38:52
我看到您已经解决了这个问题,我赞同您的回答,因为使用方便对象TextField确实比自己创建PdfFormField更容易。
为了完整起见,我添加了一个额外的答案,以澄清最初的错误所在。
在下面的代码行中,您混合了两个概念:
combo.SetFieldFlags(PdfAnnotation.FLAGS_PRINT);字段在字段字典中进行描述,您可以定义字段标志,使字段成为只读、必填、多选等。您可以在字段字典的/Ff条目中找到字段标志的值。
每个字段对应于零个、一个或多个小部件注释。小部件注释是字段的可视化表示,并使用注释字典对其进行描述。您可以定义注释标志,例如,定义此类注释的可见性。您可以在注释字典的/F条目中找到注释标志。
当一个字段对应于一个小部件注释时(这是大多数表单的情况),字段字典及其小部件注释的字典将合并到一个字典中。这个字典可以有一个/Ff和一个/F条目。
在您的代码中,您将注释标志定义为字段标志。您将一个应该在/F条目中的值放入/Ff条目中。这是错误的,它解释了为什么你的代码“不能工作”。通过将现有值替换为具有完全不同含义的值,您实际上正在破坏您的字段字典。
您应该使用以下行来更正您的代码:
combo.Flags = PdfAnnotation.FLAGS_PRINT;这样,您就可以完整地使用/Ff值来更改/F值。
https://stackoverflow.com/questions/24765167
复制相似问题