我有代码可以创建 pdf 文档,在从中获取 acroform 字段并将它们保存在 vector 中之后。
PDFDocument pdfDocument = new PDFDocument(pdfPath, null);
AcroForm acroForm = pdfDocument.getAcroForm();
Vector fieldList = acroForm.getFieldList();
System.out.println("fieldList: " + fieldList);
Sysout 返回此:
[[Field FullName=amtApprvd_1_2 Type=Tx], [Field FullName=percentIrateInit_1_2 Type=Tx], [Field FullName=borrowerName Type=Tx]]
现在我想在ArrayList中保存字段名称(例如amtApprvd_1_2)。我怎样才能做到这一点?
我能够使用枚举和迭代器,但只能将它们保存为对象,该对象既有字段名称又有类型。但我只想要 ArrayList 中的字段名称。请指教。
AcroForm 的 API 来自 com.qoppa.pdf.form
最佳答案
不知道AcroForm
的API和 getFieldList()
方法,但类似这样:
Vector<Field> fieldList = acroForm.getFieldList();
ArrayList<String> fieldNames = new ArrayList<>(fieldList.size());
for (Field field : fieldList)
fieldNames.add(field.getFullName());
这假设 getFieldList()
返回 Vector<Field>
,不仅仅是一个原始的Vector
.
关于java - 如何将 vector 中的元素放入ArrayList中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36870714/