【发布时间】:2019-08-06 16:59:34
【问题描述】:
我尝试将 pdf 中的表单字段 (PDAcroForm.flatten()) 展平,该 pdf 在之前的步骤中从 .xfdf 文件中填充。
预期的结果是用文本替换可编辑框。
但是,我在拼合后将文本填入表单 (output02.pdf) 的 PDF 中,所有添加的文本现在都完全消失了,所以我得到一个空格而不是表单值 (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"));
编辑:
通过表单菜单在现有 PDF 上创建带有 Adobe Acrobat Pro 10.1.1 的表单元素,并将 pdf 保存为 sample5.pdf 和 test.pdf。
【问题讨论】:
-
一种方法是手动将表单字段中的文本写入 PDF 的内容流,我们自己根据现有的 x、y、w、h 框和字体大小计算位置,但这会与大小设置为
Auto的字段分开。 -
那里 /V 条目(字段值)是名称,但应该是字符串。我希望这不是 PDFBox 错误...
-
@TilmanHausherr 通过表单菜单在现有 PDF 上使用
Adobe Acrobat Pro10.1.1创建了这些表单元素,并将 pdf 保存为sample5.pdf和test.pdf。 -
您现在指的是哪个文件的
/V条目? -
我的印象是拥有最新版本。事实上,它解决了它。想要一个我能接受的答案吗?
标签: pdf pdfbox flatten-pdf