我需要使用itextsharp检查表单字段(文本字段)是否为多行。我有以下代码,但它似乎不起作用。在密钥中我有表单字段名称。
iTextSharp.text.pdf.PdfDictionary dic = new PdfDictionary();
dic = (iTextSharp.text.pdf.PdfDictionary)form.GetFieldItem(key).GetMerged(0);
//Check if textbox is multiline. If yes then do not truncate.
if (!(dic.GetAsNumber(iTextSharp.text.pdf.PdfName.FF) != null && dic.GetAsNumber(iTextSharp.text.pdf.PdfName.FF).IntValue == iTextSharp.text.pdf.PdfFormField.FF_MULTILINE))
{
//some code
}
答案 0 :(得分:2)
如有疑问,请查看book,更具体地chapter 13,您可以在其中找到名为InspectForm的示例,您可以从中复制此代码段。
flags = dict.GetAsNumber(PdfName.FF).IntValue;
if ((flags & BaseField.MULTILINE) > 0)
sb.Append(" -> multiline");
您的代码无效的原因:您假设MULTILINE
标志是唯一设置的标志。它很可能不是。 FieldFlags(FF
)值是一个位集,MULTILINE
只负责集合中的一位。