【问题标题】:Java - PDFBox - PDF with JBIG2 imageJava - PDFBox - 带有 JBIG2 图像的 PDF
【发布时间】:2014-03-17 15:38:03
【问题描述】:

我在使用 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
但它对我不起作用,或者我没有得到正确的解决方案。

有人可以帮我解决吗?

提前致谢。

【问题讨论】:

标签: java image pdf pdfbox jbig2


【解决方案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>

More information here.

【讨论】:

    猜你喜欢
    • 2019-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-06
    • 2013-12-23
    • 2014-04-16
    • 1970-01-01
    相关资源
    最近更新 更多