我在使用 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
但它对我不起作用或者我没有得到正确的解决方案。
有人可以帮我解决这个问题吗?
提前致谢。
最佳答案
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>
关于Java - PDFBox - 带有 JBIG2 图像的 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22458667/