I\'m working on dynamically filling in the fields on a pdf document using ITextSharp. I\'d like to be able to determine the \"export value\" of the checkbox is from the cod
This was the final method I used to get it working based on the others:
public string GetCheckBoxExportValue(AcroFields fields, string cbFieldName)
{
AcroFields.Item item = fields.GetFieldItem(cbFieldName);
if (item.values.Count > 0)
{
PdfDictionary valueDict = item.values[0] as PdfDictionary;
PdfDictionary appDict = valueDict.GetAsDict(PdfName.AP);
if (appDict != null)
{
PdfDictionary normalApp = appDict.GetAsDict(PdfName.N);
foreach (PdfName curKey in normalApp.Keys)
{
if (!PdfName.OFF.Equals(curKey))
{
// string will have a leading '/' character
return curKey.ToString();
}
}
}
PdfName curVal = valueDict.GetAsName(PdfName.AS);
if (curVal != null)
{
return curVal.ToString();
}
}
return null;
}