Reputation: 31
I'm getting a problem using PDFBox API. I have a PDF file with a JBIG2 image in it and I want to read it out and create a JPEG or PNG file with the PDF content. Unfortunately I'm only getting a black image.
My code is:
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);
}
I already checked this: https://issues.apache.org/jira/i#browse/PDFBOX-1067
But it did not work for me or I not getting the right solution.
Can someone help me out with it?
Thanks in advance.
Upvotes: 2
Views: 2890
Reputation: 7012
JBIG2 images are handled by an optional extension, that probably it isn't supplied by you:
Reading JBIG2 images: JBIG2 ImageIO or JBIG2-Image-Decoder
Just load this dependency from Maven:
<dependency>
<groupId>com.levigo.jbig2</groupId>
<artifactId>levigo-jbig2-imageio</artifactId>
<version>1.6.5</version>
</dependency>
Upvotes: 3