读取使用iText的夏普复选框,单选按钮名称和值从PDF [英] Read Check Box, Radio Button Name and values from PDF using iText Sharp
问题描述
我有一个可填写的PDF包含复选框和单选按钮和文本框。
我要如何将CheckBox名称和它的价值也是我们怎么知道这是一个复选框/单选按钮?
我使用iTextSharp的,并有看看我下面code
PdfReader pdfReader =新PdfReader(文件名);
pdfReader.SelectPages(37);
MemoryStream的ostream的=新的MemoryStream();
PdfStamper模子=新PdfStamper(pdfReader,ostream的);
AcroFields形式= stamper.AcroFields;
如果(form.Fields.Count()大于0)
{
IDictionary的<字符串,AcroFields.Item> ODIC = form.Fields; 的foreach(在oDic.Keys串字段名)
{
//字段名 - 复选框名称;我需要确认是一个复选框...
} 的foreach(AcroFields.Item OITEM在oDic.Values)
{
//我们怎么复选框值
}
}
以下code可以帮助你,如果你仍然需要它。它仅适用于AcroForms
INT BUTTON = 1;
INT CHECK_BOX = 2;
INT RADIO_BUTTON = 3;
INT TEXT_FIELD = 4;
INT LIST_BOX = 5;
INT COMBO_BOX = 6;PdfReader pdfReader =新PdfReader(路径);
AcroFields AF = pdfReader.AcroFields;的foreach(在af.Fields VAR场)
{
布尔isRadio = RADIO_BUTTON == af.GetFieldType(field.Key));
}
编辑:
另外,field.Key是字段的名称和field.Value是在它的值
有关复选框,如果(field.Value ==是),则选择......如果是别的,它没有被选中。
编辑:
和我刚刚发现TRO如何让单选按钮选项,如果你需要他们。
的myKey K =新的myKey(field.Key,af.GetField(field.Key),af.GetFieldType(field.Key));
如果(k.isRadio())
{
尝试{k.options.AddRange(af.GetAppearanceStates(k.key)); }
赶上{}
}
Keys.Add(K);
I have a fillable PDF contains CheckBoxes and RadioButtons and TextBox.
How do i get the CheckBox Name and its value also how do we know that it is a checkbox / Radio Button?
i'm using iTextSharp and have look at my below code
PdfReader pdfReader = new PdfReader(FileName);
pdfReader.SelectPages("37");
MemoryStream oStream = new MemoryStream();
PdfStamper stamper = new PdfStamper(pdfReader, oStream);
AcroFields form = stamper.AcroFields;
if (form.Fields.Count() > 0)
{
IDictionary<string,AcroFields.Item> oDic= form.Fields;
foreach (string FieldName in oDic.Keys)
{
//FieldName - CheckBox name; i need to confirm that is a Checkbox...
}
foreach (AcroFields.Item oItem in oDic.Values)
{
// how do we get check box values
}
}
The following code may help you out, if you still need it. It only works for AcroForms
int BUTTON = 1;
int CHECK_BOX = 2;
int RADIO_BUTTON = 3;
int TEXT_FIELD = 4;
int LIST_BOX = 5;
int COMBO_BOX = 6;
PdfReader pdfReader = new PdfReader(path);
AcroFields af = pdfReader.AcroFields;
foreach (var field in af.Fields)
{
bool isRadio = RADIO_BUTTON == af.GetFieldType(field.Key));
}
Edit:
Also, field.Key is the name of the field and field.Value is the value at it.
For checkboxes, if(field.Value == "Yes") then it is selected... if it is anything else, it is not selected.
Edit:
And I just found how tro get Radio Button options, if you are needing them.
myKey k = new myKey(field.Key, af.GetField(field.Key), af.GetFieldType(field.Key));
if (k.isRadio())
{
try { k.options.AddRange(af.GetAppearanceStates(k.key)); }
catch { }
}
Keys.Add(k);
这篇关于读取使用iText的夏普复选框,单选按钮名称和值从PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!