Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PDF Box generating blank images due to JBIG2 Images in it

Let me give you an overview of my project first. I have a pdf which I need to convert into images(One image for one page) using PDFBox API and write all those images onto a new pdf using PDFBox API itself. Basically, converting a pdf into a pdf, which we refer to as PDF Transcoding.

For certain pdfs, which contain JBIG2 images, PDFbox implementation of convertToImage() method is failing silently without any exceptions or errors and finally, producing a PDF, but this time, just with blank content(white). The message I am getting on the console is:

Dec 06, 2013 5:15:42 PM org.apache.pdfbox.filter.JBIG2Filter decode
SEVERE: Can't find an ImageIO plugin to decode the JBIG2 encoded datastream.
Dec 06, 2013 5:15:42 PM org.apache.pdfbox.pdmodel.graphics.xobject.PDPixelMap getRGBImage
SEVERE: Something went wrong ... the pixelmap doesn't contain any data.
Dec 06, 2013 5:15:42 PM org.apache.pdfbox.util.operator.pagedrawer.Invoke process
WARNING: getRGBImage returned NULL

I need to know how to resolve this issue? We have something like:

import org.apache.pdfbox.filter.JBIG2Filter; 

which I don't know how to implement.

I am searching on that, but to no avail. Could anyone please suggest?

like image 433
Vaibhav Sawalkar Avatar asked Dec 06 '13 13:12

Vaibhav Sawalkar


3 Answers

I had the same problem and I fixed it by adding this dependency in my pom.xml :

<dependency>
    <groupId>org.apache.pdfbox</groupId>
    <artifactId>jbig2-imageio</artifactId>
    <version>3.0.2</version>
</dependency>

Good luck.

like image 125
youssouf diarra Avatar answered Oct 16 '22 19:10

youssouf diarra


Take a look at this ticket in PDFBox https://issues.apache.org/jira/browse/PDFBOX-1067 . I think the answer to your question is:

  1. to make sure that you have JAI and the JAI-ImageIO plugins installed for your version of Java: decent installation instructions are available here: http://docs.geoserver.org/latest/en/user/production/java.html
  2. to use the JBIG2-imageio plugin, (newer versions are licensed under the Apache2 license) https://github.com/levigo/jbig2-imageio/
like image 12
adam Avatar answered Oct 16 '22 20:10

adam


I had the exact same problem. I downloaded the jar from jbig2-imageio and I just included it in my project's application libraries, and it worked right out of the box. As adam said, it uses GPL3.

like image 3
lost in binary Avatar answered Oct 16 '22 18:10

lost in binary