0

I got a pdf file which I open with PDFBox (version 2.0.20, but should be not version related). The file has a page which is actually a JPEG2000 image.

First I got the well known error : Cannot read JPEG2000 image: Java Advanced Imaging (JAI) Image I/O Tools are not installed.

I added the JAI core tools and the corresponding jpeg2000 plugin in my POM:

<dependency>
<groupId>com.github.jai-imageio</groupId>
<artifactId>jai-imageio-core</artifactId>
<version>1.4.0</version>
</dependency>

<dependency>
<groupId>com.github.jai-imageio</groupId>
<artifactId>jai-imageio-jpeg2000</artifactId>
<version>1.3.0</version>
</dependency> 

And everything works fine!

BUT: the internet says, that the usage of jai-imageio-jpeg2000 infringes patents if you use without paying.

Therefore my question is, can I make PDFBox use a different module? I understood that twelvemonkeys is a good choice and I have read some threads where it was tested. But I have found no howto, HOW to make pdfbox switch to e.g. twelvemonkeys.

I removed the above from the POM and added the twelvemonkeys, but that does not work (got again the error message from above)

<dependency>
<groupId>com.twelvemonkeys.imageio</groupId>
<artifactId>imageio-jpeg</artifactId>
<version>3.8.2</version>
</dependency>

Huebi
  • 41
  • 6
  • 2
    JPEG and JPEG2000 are different formats (with different technologies and patents). The TwelveMonkeys ImageIO JPEG plugin can only read files in JPEG format – Harald K Jun 28 '22 at 07:49
  • Thanks! Just by chance, any proposal for an alternative? – Huebi Jun 28 '22 at 12:00
  • 1
    I suggest you try [Software Recommendations](https://softwarerecs.stackexchange.com). – Harald K Jun 28 '22 at 12:18
  • So I decided to go with jdeli. I added their library and then I checked out their plugin project from github and added both to my project. Running in my dev environment (Eclipse) works without any problem. BUT: when I exported the project as runnable jar, it runs into errors. I figured out that having the jdeli plugin in parallel to the twelvemonkeys jpeg plugin in command line gives the twelvemonkeys plugin priority which is not able to decode the jpeg200, as we discussed above. I removed twelvemonkey-jpeg from project and it works. So question is: how does java decide prios for JAI plugins? – Huebi Jul 03 '22 at 17:58

1 Answers1

0

So finally I used the JDeli library. It is a commercial library and at time of writing you need to pay between 800$ per year or a one-time payment of 4000$. But based on the fact that with patent problem of the JJ2000 code you might run into even bigger issues, I decided for our project to go with it.

Money is one topic but do my jpeg2000 problems with the pdfbox disappear? Yes!

I followed the instructions on the web page (https://support.idrsolutions.com/jdeli/tutorials/add-jdeli-as-a-maven-dependency):

I downloaded the trial lib, added to my maven archive and added this to my pom.xml:

<dependency>
    <groupId>com.idrsolutions</groupId>
    <artifactId>jdeli</artifactId>
    <version>1.0</version>
</dependency>

As I wanted to use the product as JAI plugin I also checked out the git project for the plugin : https://github.com/idrsolutions/JDeli_ImageIO_Plugin

After checkout I did the mvn install and the plugin was in my mvn repo. I added then also the plugin as dependency to my pom.xml:

<dependency>
    <groupId>com.idrsolutions</groupId>
    <artifactId>JDeli_ImageIO_Plugin</artifactId>
    <version>1.0</version>
</dependency>

From here my pdfs with the jpeg2000 images inside could be loaded with pdfbox as expected.

So this will not answer my question how to use twelvemonkeys to read pdfs with jpeg2000 inside with pdfbox as it is not possible (see above), but it provides an alternative which worked at least for me as long as you can accept to pay for the library.

Huebi
  • 41
  • 6