我正在使用iText-7
,并尝试读取pdfForm
(在LibreOffice
中生成)并为一个文本字段(Form仅具有一个文本字段)设置值。但是我变得异常例外
Exception in thread "main" java.lang.NumberFormatException: For input string: "9.014"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:580)
at java.lang.Integer.<init>(Integer.java:867)
at com.itextpdf.forms.fields.PdfFormField.splitDAelements(PdfFormField.java:2114)
at com.itextpdf.forms.fields.PdfFormField.getFontAndSize(PdfFormField.java:2058)
at com.itextpdf.forms.fields.PdfFormField.regenerateField(PdfFormField.java:1639)
at com.itextpdf.forms.fields.PdfFormField.setValue(PdfFormField.java:939)
at com.itextpdf.forms.fields.PdfFormField.setValue(PdfFormField.java:900)
执行时
form.getField(key).setValue("1234567890");
这是执行上述任务的代码:
PdfReader reader = new PdfReader(src);
PdfDocument pdf = new PdfDocument(reader, new PdfWriter(dest));
PdfAcroForm form = PdfAcroForm.getAcroForm(pdf, true);
Map<String, PdfFormField> tf = form.getFormFields();
for (String key : tf.keySet()) {
System.out.println("Key: |" + key + "| \t value: " +
tf.get(key).getValueAsString());
form.getField(key).setValue("1234567890");
}
pdf.close();
我能够读取该字段的值,但不能回写。
link到pdf