- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我写了下面的小Java main
方法。它接受一个(出于测试目的而硬编码!)PDF 文档,我知道该文档包含表单中的 Activity 元素,需要将其展平。
public static void main(String [] args) {
try {
// for testing
Tika tika = new Tika();
String filePath = "<path-to>/<pdf-document-with-active-elements>.pdf";
String fileName = filePath.substring(0, filePath.length() -4);
File file = new File(filePath);
if (tika.detect(file).equalsIgnoreCase("application/pdf")) {
PDDocument pdDocument = PDDocument.load(file);
PDAcroForm pdAcroForm = pdDocument.getDocumentCatalog().getAcroForm();
if (pdAcroForm != null) {
pdAcroForm.flatten();
pdAcroForm.refreshAppearances();
pdDocument.save(fileName + "-flattened.pdf");
}
pdDocument.close();
}
}
catch (Exception e) {
System.err.println("Exception: " + e.getLocalizedMessage());
}
}
什么样的测试会断言 File(<path-to>/<pdf-document-with-active-elements>-flattened.pdf)
事实上,由这段代码生成的代码会是平坦的吗?
最佳答案
What kind of test would assert that the file generated by this code would, in fact, be flat?
重新加载该文档并检查其 PDAcroForm
中是否有任何表单字段(如果有 PDAcroForm
)。
如果您想彻底了解,还可以遍历页面并确保不再有与它们关联的 Widget 注释。
为了真正彻底,在拼合之前另外确定字段位置和内容,并将这些位置的文本提取应用到拼合的 pdf 中。这证实了表单不仅被丢弃而且确实被压平了。
关于java - apache pdfbox - 如何测试文档是否被展平?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59875133/
在 apache PDFBox 网站上,http://pdfbox.apache.org/2.0/migration.html ,PDF 渲染示例。 ImageIOUtil.writeImage(bi
我们正在使用 PDFBox 从 PDF 中提取文本。 某些 PDF 的文本无法正确提取。 下图显示了 PDF 中的一部分作为图像: 文本提取后,我们得到以下文本: 3, 8 5 EU R 1 Nett
任何人都可以帮我了解如何使用 Apache PDFBOX 将文本替换为图像吗? 最佳答案 import java.io.File; import java.io.IOException;
我正在升级我的项目中的库并将 pdfbox 从 0.6.7 升级到 1.6.0 版,但找不到 LucenePDFDocument 类。 Apache 页面上的文档/教程中仍然提到了该类。有任何想法吗?
在我的应用程序中,我使用 Apache PDFBox 来呈现 PDF 文件并进行静音打印。 PDFBox 可以很好地渲染 PFD,但我遇到了问题 缩放 来到图片。 在这里我想在打印 PDF 之前设置页
我正在使用使用 pdfbox 2.0.3 的 Apache Tika 1.14。 我用它来提取文件的文本内容。在生产模式下处理许多文件时,我会记录许多如下语句: WARN o.a.p.pdmodel
有人能给我一个关于如何使用 Apache PDFBox 将 PDF 文件转换为不同图像的示例吗(PDF 的每一页一个图像)? 最佳答案 1.8.* 版本的解决方案: PDDocument docume
我正在使用 PDF BOX 获取 PDF 文本的颜色信息。我可以使用以下代码获得输出。但是我的疑问是 StrokingColor 代表什么,Non stroking color 代表什么。基于此,我将
我终于成功地让 PDFBox 打印我的 unicodes。但现在,我想了解我提出的解决方案。下面的代码可以运行并将 ≥ 打印到页面上。 有两件事不起作用: 改变PDType0Font.load(doc
我正在使用 PDF BOX 获取 PDF 文本的颜色信息。我可以使用以下代码获得输出。但是我的疑问是 StrokingColor 代表什么,Non stroking color 代表什么。基于此,我将
我的项目要求在 Apache pdfbox api 的帮助下生成发票。截至目前,我可以在生成的 pdf 中插入图像、文本,但在生成表格时发现困难。我什至找不到单个示例模板。如果有人有请提供链接。 注意
我如何使用 PDFBox 2.0.0 获取字段位置?在 Pdfbox 1.8.11 中,我是这样工作的: String formTemplate = "Template.pdf
我在我们的一个项目中使用了 CMS Magnolia。在日志文件中有很多错误,例如: 字体 ArialMT 中使用的 OpenType 布局表未在 PDFBox 中实现 这对 PDF 有什么影响?可以
我一直在使用 PDFBox 1.8 来处理 pdf。现在我计划转向 PDFBox 2.0-RC-2。我在迁移时遇到一些问题。 在 PDFBox 1.8 中,我曾经使用以下方法从 PDPage 获取 t
我正在使用 PDFBox 1.7.0(由于生产服务器中的版本较旧,我无法选择该版本)。我正在尝试将图像添加到已有 Logo 的现有 PDF 中。当我添加新图像时,旧图像就像被替换一样消失了。 // U
我正在使用 Apache PDFBox 库 在可填写的 PDF 表格 (AcroFrom) 中填写信息。完成信息填写后,我需要编写一个新的PDF文件(不可编辑格式)。 我尝试了 setReadOnly
在对 PDDocument 进行数字签名后,我已关闭 Apache PDFBox 中的 PDDocument。我收到警告:当我关闭我的实例时,You did not close PDF Documen
我在 wildfly 模块中使用 Apache Tika(tika-app 1.17)。当我开始提取 PDF 时,它总是抛出错误: java.lang.NoClassDefFoundError: Co
我尝试使用 pdfbox 并使用 groovy 进行编译,但我不知道 这是我使用的代码 groovyc main.groovy 但不起作用,请帮助我 this.class.classLoader.ro
我在 wildfly 模块中使用 Apache Tika(tika-app 1.17)。当我开始提取 PDF 时,它总是抛出错误: java.lang.NoClassDefFoundError: Co
我是一名优秀的程序员,十分优秀!