pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joel Hirsh <joelehi...@gmail.com>
Subject PDFBox JPEG2000 and Tomcat - Revisited
Date Wed, 01 Aug 2018 15:42:03 GMT
I was having a problem a month ago with reading JPEG2000 files on tomcat,
that seemed identical to what is described in a posting to this list by
Chris Gamache <https://plus.google.com/u/0/101607728077454498498?prsrc=4>
 <cgamache@gmail.com> on Jun 21 2017 with the subject "PDFBox JPEG2000 and
Tomcat".  Basically PDFBox was 'forgetting' about the JPEG2000 library at
some point, and getting an error when reading a JPEG2000 file.

I reached out to Chris and he was kind enough to offer me his solution,
which is to check for whether JPEG2000 is loaded before each call to
PDFBox, and then reload it.  And that seemed to resolve my problem.

I recently upgraded to PDFBox 2.0.11, and removed the library
levigo-jbig2-imageio-1.6.5.jar as those entry points were now being defined
in pdfbox-app-2.0.11.jar.

And what appears to be the same error is back.  Running one JPEG2000 image
is fine, but at some point I get the error

java.lang.NoClassDefFoundError: Could not initialize class
org.apache.pdfbox.jbig2.JBIG2ImageReader
  at
org.apache.pdfbox.jbig2.JBIG2ImageReaderSpi.createReaderInstance(JBIG2ImageReaderSpi.java:117)
  at
javax.imageio.spi.ImageReaderSpi.createReaderInstance(ImageReaderSpi.java:320)
  at javax.imageio.ImageIO$ImageReaderIterator.next(ImageIO.java:529)
  at javax.imageio.ImageIO$ImageReaderIterator.next(ImageIO.java:513)
  at org.apache.pdfbox.filter.Filter.findImageReader(Filter.java:155)
  at org.apache.pdfbox.filter.JBIG2Filter.decode(JBIG2Filter.java:67)
  at org.apache.pdfbox.cos.COSInputStream.create(COSInputStream.java:77)
  at org.apache.pdfbox.cos.COSStream.createInputStream(COSStream.java:175)
  at org.apache.pdfbox.cos.COSStream.createInputStream(COSStream.java:163)
  at
org.apache.pdfbox.pdmodel.common.PDStream.createInputStream(PDStream.java:236)
  at
org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject.createInputStream(PDImageXObject.java:695)
  at
org.apache.pdfbox.pdmodel.graphics.image.SampledImageReader.getStencilImage(SampledImageReader.java:91)
  at
org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject.getStencilImage(PDImageXObject.java:483)
  at org.apache.pdfbox.rendering.PageDrawer.drawImage(PageDrawer.java:1029)
  at
org.apache.pdfbox.contentstream.operator.graphics.DrawObject.process(DrawObject.java:62)
  at
org.apache.pdfbox.contentstream.PDFStreamEngine.processOperator(PDFStreamEngine.java:848)
  at
org.apache.pdfbox.contentstream.PDFStreamEngine.processStreamOperators(PDFStreamEngine.java:503)
  at
org.apache.pdfbox.contentstream.PDFStreamEngine.processStream(PDFStreamEngine.java:477)
  at
org.apache.pdfbox.contentstream.PDFStreamEngine.processPage(PDFStreamEngine.java:150)
  at org.apache.pdfbox.rendering.PageDrawer.drawPage(PageDrawer.java:246)
  at
org.apache.pdfbox.rendering.PDFRenderer.renderImage(PDFRenderer.java:225)
  at
org.apache.pdfbox.rendering.PDFRenderer.renderImageWithDPI(PDFRenderer.java:150)

Which is very similar to the error I got with PDFBox 2.0.7 and the levigo
jar

java.lang.NoClassDefFoundError: Could not initialize class
com.levigo.jbig2.JBIG2ImageReader
  at
com.levigo.jbig2.JBIG2ImageReaderSpi.createReaderInstance(JBIG2ImageReaderSpi.java:118)
  at
javax.imageio.spi.ImageReaderSpi.createReaderInstance(ImageReaderSpi.java:320)
  at javax.imageio.ImageIO$ImageReaderIterator.next(ImageIO.java:529)
  at javax.imageio.ImageIO$ImageReaderIterator.next(ImageIO.java:513)
  at org.apache.pdfbox.filter.Filter.findImageReader(Filter.java:120)
  at org.apache.pdfbox.filter.JBIG2Filter.decode(JBIG2Filter.java:54)
  at org.apache.pdfbox.cos.COSInputStream.create(COSInputStream.java:69)
  at org.apache.pdfbox.cos.COSStream.createInputStream(COSStream.java:167)
  at
org.apache.pdfbox.pdmodel.common.PDStream.createInputStream(PDStream.java:235)
  at
org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject.<init>(PDImageXObject.java:125)
  at
org.apache.pdfbox.pdmodel.graphics.PDXObject.createXObject(PDXObject.java:70)
  at org.apache.pdfbox.pdmodel.PDResources.getXObject(PDResources.java:409)
  at com.moneythumb.convert.i.processOperator(SourceFile:72)
  at
org.apache.pdfbox.contentstream.PDFStreamEngine.processStreamOperators(PDFStreamEngine.java:495)
  at
org.apache.pdfbox.contentstream.PDFStreamEngine.processStream(PDFStreamEngine.java:469)
  at
org.apache.pdfbox.contentstream.PDFStreamEngine.processPage(PDFStreamEngine.java:150)

Also the workaround from Chris was still in place, but did not appear to
help, although it is not specific to any packaging.  It checks whether the
reader for format 'JPEG2000' canReadRaster() and if not calls
IIORegistry.getDefaultInstance.registerApplicationClasspathSpis();.

So my take is that PDFBox inherited whatever problem was there previously
in the  JBIG2 ImageIO plugin.

And I am surprised that the workaround did not help - I assume the format
is still known at 'JPEG2000', right?

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message