如何使用 PDFbox (C#) 从 PDF 表单中获取单选按钮值
在 Java 中:
doc = PDDocument.load("C:\\Users\\347702\\Desktop\\sample_form.pdf");
List pages = doc.getDocumentCatalog().getAllPages();
PDAcroForm form = doc.getDocumentCatalog().getAcroForm();
List FieldTypes = form.getFields();
PDField pdfFields;
for (int i = 0; i < FieldTypes.size(); i++) {
pdfFields = (PDField) ((List) FieldTypes).get(i);
if (pdfFields instanceof PDRadioCollection)
{
String iAsString = Integer.toString(k);
System.out.println(iAsString);
type = "RadioButton";
System.out.println("Radio Button" + " "
+ pdfFields.getFullyQualifiedName() + " ");
List kids = pdfFields.getKids();
for (Object kid : kids) {
if (kid instanceof PDCheckbox) {
PDCheckbox checkbox = (PDCheckbox) kid;
String Name = checkbox.getOnValue();
System.out.println(Name);
}
}
上面的 java 代码已经成功运行(成功返回 Radiobuttons 的子级),但是当在 c# 中实现相同的逻辑时,它没有按预期运行
下面是我的 C# 代码:
else if (pdfFields is PDRadioCollection)
{
System.Console.WriteLine("Radio Button" + " "
+ pdfFields.getFullyQualifiedName() + " ");
List kids = pdfFields.getKids();
System.Console.WriteLine(kids);
for (int w = 0; w < kids.size(); w++)
{
kids.get(w);
System.Console.WriteLine(kids.get(w)); ---- > Return null
System.Console.WriteLine(kids.get(w).ToString()); -- > Return null
}
}
有什么可以帮忙的吗谢谢