我正在使用ITextSharp动态填写pdf文档中的字段.我希望能够确定复选框的"导出值"来自代码隐藏,以便确定在应该检查时向该复选框发送什么值.我过去使用过的大多数文档对每个复选框都有相同的导出值,但我正在使用的那个文件因复选框而异.我可以浏览所有文本框并使它们保持一致但如果我可以确定这些复选框在运行时的导出值并相应地设置它们将在未来节省大量时间.
提前致谢!
我尝试在C#中实现下面的解决方案,最后得到以下代码:
public string GetCheckBoxExportValue(AcroFields pdfDocument, string checkBoxFieldName)
{
AcroFields.Item item = pdfDocument.GetFieldItem(checkBoxFieldName);
if (item.values.Count > 0)
{
PdfDictionary valueDict = item.GetValue(0);
PdfDictionary appearanceDict = valueDict.GetAsDict(PdfName.AP);
// if there's an appearance dict at all, one key will be "Off", and the other
// will be the export value... there should only be two.
if (appearanceDict != null)
{
foreach (PdfName curKey in appearanceDict.Keys)
{
if (!PdfName.OFF.Equals(curKey))
{
return curKey.ToString(); // string will have a leading '/' character
}
} …Run Code Online (Sandbox Code Playgroud)