Hi,
I use Aspose.Words in order to edit and then convert a .docx file to pdf file format. These files may contain JPG images. In some cases(depending on the image inside the .docx document) I get the following messages in my application logs:
Aspose.Words for Java is limited with JDK's built-in image encoders/decoders.
In order to improve reading/writing quality use the following external graphics libraries:
* ImageMagick
- Download and install ImageMagick from https://imagemagick.org/script/download.php
- Windows users will have to set up the path to ImageMagick via IM4JAVA_TOOLPATH or ProcessStarter.setGlobalSearchPath(myPath), e.g. IM4JAVA_TOOLPATH=C:\Program Files\ImageMagick-7.0.8-Q16
- Download im4java https://sourceforge.net/projects/im4java/files/
- Copy im4java-1.4.0.jar to CLASSPATH or copy to JDK_HOME/jre/lib/ext directory.
* Java Advanced Imaging API
- Download jai_codec and add it to application classpath https://mvnrepository.com/artifact/javax.media/jai_codec/1.1.3
- Download jai_core and add it to application classpath https://mvnrepository.com/artifact/javax.media/jai-core/1.1.3
- Download jai_imageio and add it to application classpath https://mvnrepository.com/artifact/javax.media/jai_imageio/1.1.1
I installed ImageMagick and I added the Java Advanced Imaging API required jars in my application’s classpath. Now I don’t get this message. However, when I try to convert a .docx file to .pdf I get the following stacktrace:
Preformatted textError: One factory fails for the operation "jpeg"
Occurs in: javax.media.jai.ThreadSafeOperationRegistry
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at javax.media.jai.FactoryCache.invoke(FactoryCache.java:122)
.
.
.
Caused by: javax.media.jai.util.ImagingException: All factories fail for the operation "jpeg"
at javax.media.jai.OperationRegistry.invokeFactory(OperationRegistry.java:1687)
at javax.media.jai.ThreadSafeOperationRegistry.invokeFactory(ThreadSafeOperationRegistry.java:473)
at javax.media.jai.registry.RIFRegistry.create(RIFRegistry.java:332)
at com.sun.media.jai.opimage.StreamRIF.create(StreamRIF.java:102)
... 180 more
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at javax.media.jai.FactoryCache.invoke(FactoryCache.java:122)
at javax.media.jai.OperationRegistry.invokeFactory(OperationRegistry.java:1674)
... 183 more
Caused by: java.lang.NoClassDefFoundError: com/sun/image/codec/jpeg/JPEGCodec
at com.sun.media.jai.codecimpl.JPEGImage.<init>(JPEGImageDecoder.java:106)
at com.sun.media.jai.codecimpl.JPEGImageDecoder.decodeAsRenderedImage(JPEGImageDecoder.java:46)
at com.sun.media.jai.opimage.CodecRIFUtil.create(CodecRIFUtil.java:88)
at com.sun.media.jai.opimage.JPEGRIF.create(JPEGRIF.java:43)
... 189 more
Caused by: java.lang.ClassNotFoundException: com.sun.image.codec.jpeg.JPEGCodec
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 193 more
I am using “Aspose.Words 20.1” and my Java application runs with “openjdk 11.0.4-redhat 2019-07-16 LTS” on a “Windows 10 64-bit” workstation.
What I actions should I perform in order to overcome this issue?