Java - PDFBox - 带JBIG2图像的PDF

时间:2014-03-17 15:38:04

标签: java image pdf pdfbox jbig2

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

有人能帮帮我吗?

提前致谢。

1 个答案:

答案 0 :(得分:1)

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

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

只需从Maven加载此依赖项:

HiveContext

More information here

相关问题