Search code examples
javapdfboxjpeg2000

Printing JPEG2000 with PDFBOX


I'm testing the viability of jai-imageio-core and jai-imageio-jpeg2000 for a project that prints a PDF containing a JPEG2000 encoded image(s) using pdfbox-app.

The docs for PDFBOX state the following:

These [JPEG2000] libraries are optional and will be loaded if present on the classpath [...].

As a base-line, I'm trying the following:

 java -cp "./jai-*.jar" -jar pdfbox-app-2.0.29.jar PrintPDF jpeg2000.pdf

However, PDFBOX says:

Aug 23, 2023 1:38:58 PM org.apache.pdfbox.contentstream.PDFStreamEngine operatorException
SEVERE: Cannot read JPEG2000 image: Java Advanced Imaging (JAI) Image I/O Tools are not installed

... which is the same it says when the JPEG2000 libraries are NOT on the classpath.

What am I doing wrong?


Solution

  • AFAIK -cp and -jar can't be mixed. Here's what I just tried and it worked:

    java -cp "pdfbox-app-2.0.29.jar;lib/*" org.apache.pdfbox.tools.PrintPDF -printerName "Microsoft Print to PDF" XXXX\jpeg2000.pdf
    

    (On linux the ";" in the classpath needs to be replaced with ":")