Reputation: 183
I convert pdfs to images using jpedal. This works fine for most of the pdfs but some containing jpeg2000 i continue receiving the following error:
java.lang.RuntimeException: JPeg 2000 Images needs the VM parameter -Dorg.jpedal.jai=true switch turned on
at org.jpedal.parser.PdfStreamDecoder.decodeStreamIntoObjects(Unknown Source)
at org.jpedal.parser.PdfStreamDecoder.decodePageContent(Unknown Source)
at org.jpedal.PDFtoImageConvertor.convert(Unknown Source)
at org.jpedal.PdfDecoder.getPageAsImage(Unknown Source)
at org.jpedal.PdfDecoder.getPageAsImage(Unknown Source)
at com.....
I already set the JVM Parameter in the JAVA_OPTS, the run configuration of my tomcat and also in program code using:
System.setProperty("org.jpedal.jai", "true");
PdfDecoder decode_pdf = new PdfDecoder(true);
FontMappings.setFontReplacements();
decode_pdf.openPdfArray(pdf_file);
also the 3 JAI libs are on my build path.
So I don't know what else I have to do?
My complete code for the conversion is:
List<BufferedImage> images = new LinkedList<BufferedImage>();
System.setProperty("org.jpedal.jai", "true");
PdfDecoder decode_pdf = new PdfDecoder(true);
FontMappings.setFontReplacements();
decode_pdf.openPdfArray(pdf_file);
decode_pdf.setExtractionMode(0, 1f); //do not save images
for (int i = 1; i<= decode_pdf.getPageCount(); i++)
{
images.add(decode_pdf.getPageAsImage(i));
}
decode_pdf.closePdfFile();
Any sugestions?
Upvotes: 2
Views: 1497
Reputation: 9816
Activate jai for jpedal
System.setProperty("org.jpedal.jai", "true");
A better solution (than the article from Mark Stephens blog) is to re-register the provider, because this only has to be done once:
IIORegistry registry = IIORegistry.getDefaultInstance();
registry.registerServiceProvider(new com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageWriterSpi());
registry.registerServiceProvider(new com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageReaderSpi());
Of course JAI libs need to be in the classpath to work correctly.
Upvotes: 2