扁平化表单字段会删除内容

Flattening Form fields removes content

我尝试将 pdf 中的表单字段 (PDAcroForm.flatten()) 展平,该 pdf 在之前的步骤中从 .xfdf 文件中填充。 预期结果是将可编辑框仅替换为文本。

不过我是从PDF里面的文字填写表格的(output02.pdf) after flattening, all added text is now completely gone, so I get a blank spaces instead of the form values (output03.pdf).

放一个complete example on github,包含PDF文件(输入和生成的输出),不过这里只是展平的部分:

// in Main.java, function flatten()

PDDocument pdf_document = PDDocument.load(new File("output02.pdf"));  //from step before, merged & filled pdf files.

List<PDField> the_fields = new ArrayList<PDField>();
for (PDField field: pdf_document.getDocumentCatalog().getAcroForm().getFieldTree()) {
    the_fields.add(field);
}
System.out.println("Flattening fields: " + Arrays.stream(the_fields.toArray()).map(field -> ((PDField)field).getFullyQualifiedName()).collect(Collectors.joining(", ","[","]")));
pdf_document.getDocumentCatalog().getAcroForm().flatten(the_fields, true);
pdf_document.save(new File("output03.pdf"));

The text filled in is gone, too

编辑:
通过表单菜单在现有 PDF 上使用 Adobe Acrobat Pro 10.1.1 创建这些表单元素,并将 pdf 简单地保存为 sample5.pdftest.pdf.

这是一个自 2.0.5 two years ago 以来已修复的错误。由于该错误,xfdf 文件中的字段值被分配为名称而不是字段字典的 /V 条目(用于值)中的字符串。正因为如此,场上的出场流中,没有什么可看的。因此展平后什么都没有。

始终使用最新版本的 PDFBox。我在所有项目中都使用 maven versions plugin