java - Apache PDFBox 在转换为 PNG 时删除水平线

标签 java pdf pdfbox

我有一个 PDF,当我将其渲染为 png 时,它会删除水平线和垂直线。这是 PDF 及其外观:https://drive.google.com/file/d/1sAXwnaoZ-QJn1Kbpw85hhzV_X5zwgfkA/view?usp=sharing

这是使用 PDFBox 2.0.13 生成的 PDF 的 PNG:enter image description here

为什么这些线条被删除以及如何让它们在 PNG 中渲染?

最佳答案

问题(最有可能)是您没有安装适用于 JBIG2 图像格式的 Java ImageIO 插件,因为缺少的行和标题实际上是 JBIG2 图像。

当我在没有此类插件的情况下运行 PDFBox PDF 调试器并在其中打开 PDF 时,它也不会显示缺失的部分;将这样的插件添加到其类路径后,它突然会显示它们。

有关 PDFBox 依赖项的更多详细信息,请阅读 the PDFBox 2.0 Dependencies页。特别是

JAI Image I/O

PDF supports embedded image files, however support for some formats require third party libraries which are distributed under terms incompatible with the Apache 2.0 license:

These libraries are optional and will be loaded if present on the classpath, otherwise support for these image formats will be disabled and a warning will be logged when an unsupported image is encountered.

Maven dependencies for these components can be found in parent/pom.xml. Change the scope of the components if needed. Please make sure that any third party licenses are suitable for your project.

To include the JBIG2 library the following part can be included in your project pom.xml:

<dependency>
    <groupId>org.apache.pdfbox</groupId>
    <artifactId>jbig2-imageio</artifactId>
    <version>3.0.0</version>
</dependency>

关于java - Apache PDFBox 在转换为 PNG 时删除水平线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54641344/

相关文章:

未找到 Java Axis Web 服务项目依赖项

java - 如果 Spring MVC Controller 方法不返回值,返回什么?

java - PDFBox : PDPageContentStream's append mode misbehaving

pdfbox - 为什么当我拼合 PDF 时我的复选框消失了?

java - Minecraft forge 不加载项目纹理 1.10.2

java - 如何将 ArrayList<ArrayList<Integer>> 转换为 int[][]?

r - 在 pdf、单个表、r 中解析跨多个页面的表

python - 即使 pdf 文件被裁剪后,整个页面的内容仍然存在

pdf - ssrs 报告查看器与导出的 pdf 页数

javascript - 是否有用于 PDF 元数据的 NPM 模块?