Free Support Forum - aspose.com

Error While converting PDF to Image

Hi,
When i try to convert the each PDF Pages to images as shown in below code i get error at the statement converter.doConvert(); as given below.
I tried adding and removing jai-codec-1.1.3.jar to my lib path,But I get the same error.
I am also attaching the code and the PDF which i used to convert.

Please let me know at what point i am going wrong.
I am trying with latest ver of jar file V 2.6
String path = “c:/2.pdf”;
PdfConverter converter = new PdfConverter();
converter.bindPdf(path);
converter.doConvert();
------------------------------------------------------------------------------
Exception in thread “main” java.lang.NoClassDefFoundError: javax/media/jai/OperationRegistrySpi
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at sun.misc.Launcher$ExtClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.sun.media.jai.util.Service$LazyIterator.next(Service.java:268)
at javax.media.jai.OperationRegistry.registerServices(OperationRegistry.java:2055)
at javax.media.jai.ThreadSafeOperationRegistry.registerServices(ThreadSafeOperationRegistry.java:620)
at javax.media.jai.OperationRegistry.initializeRegistry(OperationRegistry.java:373)
at javax.media.jai.JAI.(JAI.java:566)
at com.aspose.pdf.kit.al.bq(Unknown Source)
at com.aspose.pdf.kit.bv.a(Unknown Source)
at com.aspose.pdf.kit.m6.if(Unknown Source)
at com.aspose.pdf.kit.m6.a(Unknown Source)
at com.aspose.pdf.kit.bv.a(Unknown Source)
at com.aspose.pdf.kit.rj.fE(Unknown Source)
at com.aspose.pdf.kit.PdfConverter.doConvert(Unknown Source)
at PageToImage.main(PageToImage.java:18)
Caused by: java.lang.ClassNotFoundException: javax.media.jai.OperationRegistrySpi
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at sun.misc.Launcher$ExtClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
… 29 more
-------------------------------------------------------------

Regards,
Uvaraj S

Hi Uvaraj,

You need to set the following two jar files in the CLASSPATH: jai_codec.jar and jai_core.jar.

I tried the code and file shared by you at my end and it worked fine. Please try adding the above jar files in the class path and try at your end. If you still find any issue, please do let us know.

We’re sorry for the inconvenience.
Regards,

Hi,

I was able to fix the issue.It was a problem that the jar file was there in the JRE also.

When i convert files now I am getting OutOfMemoryError.I am attaching the PDF which we used to convert.

Exception in thread “main” java.lang.OutOfMemoryError: Java heap space
at java.io.ByteArrayOutputStream.toByteArray(ByteArrayOutputStream.java:136)
at com.aspose.pdf.kit.qp.ff(Unknown Source)
at com.aspose.pdf.kit.eb.bq(Unknown Source)
at com.aspose.pdf.kit.bv.a(Unknown Source)
at com.aspose.pdf.kit.m6.if(Unknown Source)
at com.aspose.pdf.kit.m6.a(Unknown Source)
at com.aspose.pdf.kit.bv.a(Unknown Source)
at com.aspose.pdf.kit.rj.fE(Unknown Source)
at com.aspose.pdf.kit.PdfConverter.doConvert(Unknown Source)
at AsposePageToImage.main(AsposePageToImage.java:19)

I was able to fix the issue with increasing the HEAP size.
But when i execute the code i am not getting the JPG created with image in it.THe JPG is created only with text in it.
The code is available in the First Post and the PDF is available in the last post.
Please let us know where we are going wrong.

Hi Uvaraj,

Please try to increase the maximum size of JVM memory using -Xmx512m option. If it still doesn’t resolve your issue, then please do let us know.

We’re sorry for the inconvenience.
Regards,

Hi Uvaraj,

I have reproduced this problem at my end and logged it as PDFKITJAVA-14464 in our issue tracking system. Our team will look into this issue and you’ll be updated via this forum thread once the issue is resolved.

We’re sorry for the inconvenience and appreciate your patience.
Regards.


Hi,
Thanks for the update.Will be waiting for the update from your team