Search code examples
javaimagemaventomcattiff

Issue in getImageWritersByFormatName for Tiff. Getting image writer


I am trying to convert PDF to tif images. I use following code to get the image writers by format.

Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("TIFF");

        if (writers == null || !writers.hasNext()) {
            throw new ImageWritingException();
        }

This works fine when I run the application standalone in Eclipse. But when I deploy the application to tomcat server in linux, writers==null is false but !writers.hasNext is true resulting to throw Exception.

I use maven to build the project to war.

I have following dependencies in the pom file.

<dependency>
            <groupId>org.icepdf</groupId>
            <artifactId>icepdf-core</artifactId>
        </dependency>

        <dependency>
            <groupId>com.sun.media</groupId>
            <artifactId>jai_imageio</artifactId>
        </dependency>

        <dependency>
            <groupId>com.sun.media</groupId>
            <artifactId>jai-codec</artifactId>
        </dependency>

        <dependency>
            <groupId>javax.media</groupId>
            <artifactId>jai_core</artifactId>
        </dependency>

What can be the difference between two environments? How can I fix this issue?


Solution

  • Tiff support is provided by the Java Advanced Imaging plugin jai_core.jar.

    In order to work correctly, the jar file needs to be added to the JVM's ext directory, otherwise it won't register properly