0

我在使用 PDFBox API 时遇到问题。我有一个包含 JBIG2 图像的 PDF 文件,我想将其读出并创建一个包含 PDF 内容的 JPEG 或 PNG 文件。不幸的是,我只得到黑色图像。

我的代码是:

public static void copyDocumentAsImage(String path) throws IOException {
        PDDocument document = PDDocument.load(new File(path));
        String destinationDir = "myDestinationPath";
        BufferedImage img = new BufferedImage(2000, 2000, BufferedImage.TYPE_BYTE_GRAY);
        PDXObjectImage ximage = new PDJpeg(document, img);
        ximage.write2file(destinationDir);
}

我已经检查过了:https://issues.apache.org/jira/i#browse/PDFBOX-1067
但它对我不起作用,或者我没有得到正确的解决方案。

有人可以帮我解决吗?

提前致谢。

4

1 回答 1

1

JBIG2 图像由可选扩展处理,可能不是您提供的:

读取 JBIG2 图像:JBIG2 ImageIO 或 JBIG2-Image-Decoder

只需从 Maven 加载此依赖项:

<dependency>
  <groupId>com.levigo.jbig2</groupId>
  <artifactId>levigo-jbig2-imageio</artifactId>
  <version>1.6.5</version>
</dependency>

更多信息在这里

于 2016-11-16T09:06:22.823 回答