org.apache.xmlgraphics.image.loader.ImageException: The file format is not supported. No ImagePreloader found
Asked Answered
V

6

5

I am using Apache FOP 1.1(Java) to generate PDF files. It is working fine on windows machine but when I used Ubuntu machine I got this error

org.apache.xmlgraphics.image.loader.ImageException: The file format is not supported.  No ImagePreloader found

I am little bit confused. Please give me solution to sort out this problem. Thank you

Verdure answered 10/12, 2014 at 12:35 Comment(0)
V
5

I got solution from stackoverflow only. I am giving special thanks to author of this post Apache FOP in a Java Applet - No ImagePreloader found for data

With reference from above post , To give precedence to XmlGraphics
API , 
  1. I have excluded XML-graphics API from FOP jar
  2. added new maven dependency XmlGraphics API and placed above FOP dependancy
  3. so that POM will give priority


   <dependency>
        <groupId>xmlgraphics-commons</groupId>
        <artifactId>xmlgraphics-commons</artifactId>
        <version>1.4</version>
    </dependency>

    <dependency>
        <groupId>org.apache.xmlgraphics</groupId>
        <artifactId>fop</artifactId>
        <version>1.1</version>
        <exclusions>
            <exclusion>
                <artifactId>xmlgraphics-commons</artifactId>
                <groupId>org.apache.xmlgraphics</groupId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>org.apache.avalon.framework</groupId>
        <artifactId>avalon-framework-api</artifactId>
        <version>4.3.1</version>
    </dependency>

    <dependency>
        <groupId>org.apache.avalon.framework</groupId>
        <artifactId>avalon-framework-impl</artifactId>
        <version>4.3.1</version>
    </dependency>

Thank you

Verdure answered 11/12, 2014 at 6:10 Comment(2)
I have fop.jar but it does not contain xmgraphics-commons and I still have this issue. can you help me ?Rendarender
which version of FOP are you using?Verdure
D
6

The problem is a conflict between configuration files existing in META-INF/services/ both in fop jar file and xmlgraphics-commons jar file.

If you're using maven and want to avoid exclusion that may sometimes cause troubles, you can use the maven shade plugin to build a jar and force the concatenation of configuration files in META-INF/services/. A snippet like this one works for me:

   <build>
        <finalName>desired_jar_name</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.1.0</version>
                <configuration>
                    <transformers>
                        <transformer
                            implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
                        <transformer
                            implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                            <mainClass>my.main.class</mainClass>
                        </transformer>
                    </transformers>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
Domino answered 12/12, 2017 at 19:51 Comment(2)
That answer pointed me into the right direction. We encountered that problem with the SVG Image Preloader. The dirty solution was to abuse classpath precendence and load Apache FOP 2.7 before xmlgraphics-commons-2.7. We had different behaviours when starting it on our Test-Environments and Eclipse: it worked in Eclipse and nowhere else.Vincennes
This has worked a while for me, but after another upgrade of FOP the problem came back.Versatile
V
5

I got solution from stackoverflow only. I am giving special thanks to author of this post Apache FOP in a Java Applet - No ImagePreloader found for data

With reference from above post , To give precedence to XmlGraphics
API , 
  1. I have excluded XML-graphics API from FOP jar
  2. added new maven dependency XmlGraphics API and placed above FOP dependancy
  3. so that POM will give priority


   <dependency>
        <groupId>xmlgraphics-commons</groupId>
        <artifactId>xmlgraphics-commons</artifactId>
        <version>1.4</version>
    </dependency>

    <dependency>
        <groupId>org.apache.xmlgraphics</groupId>
        <artifactId>fop</artifactId>
        <version>1.1</version>
        <exclusions>
            <exclusion>
                <artifactId>xmlgraphics-commons</artifactId>
                <groupId>org.apache.xmlgraphics</groupId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>org.apache.avalon.framework</groupId>
        <artifactId>avalon-framework-api</artifactId>
        <version>4.3.1</version>
    </dependency>

    <dependency>
        <groupId>org.apache.avalon.framework</groupId>
        <artifactId>avalon-framework-impl</artifactId>
        <version>4.3.1</version>
    </dependency>

Thank you

Verdure answered 11/12, 2014 at 6:10 Comment(2)
I have fop.jar but it does not contain xmgraphics-commons and I still have this issue. can you help me ?Rendarender
which version of FOP are you using?Verdure
A
0

The equivalent solution for gradle would be:

shadowJar{
    mergeServiceFiles()
}
Azaria answered 31/1, 2021 at 12:55 Comment(0)
D
0

The above solutions did not work for me, but this one worked:

Adding xml-apis-ext.jar from https://xerces.apache.org/xml-commons/index.html

Decongestant answered 6/9, 2023 at 16:32 Comment(1)
do you have some maven or gradle dependencies available?Accordion
S
0

Ran into the same exception. Images were loading when testing in dev and local environments but not in production. Our issue was that image URLS were build using http://. What tricked us is that our server redirects http to https automatically thus when were check the image URLS manually they worked. However FOP doesn't follow redirects thus throwing the exception. So keep mind protocol as well when troubleshooting this exception/error.

Saintsimon answered 31/1 at 3:59 Comment(0)
B
0

I'm using FOP 2.9 and maven-shade-plugin 3.5. This is the only configuration which worked for me.

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>3.5.3</version>

            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>

                    <configuration>
                        <transformers>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                <resource>META-INF/services/org.apache.xmlgraphics.image.loader.spi.ImageConverter</resource>
                            </transformer>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                <resource>META-INF/services/org.apache.xmlgraphics.image.loader.spi.ImageLoaderFactory</resource>
                            </transformer>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                <resource>META-INF/services/org.apache.xmlgraphics.image.loader.spi.ImagePreloader</resource>
                            </transformer>
                        </transformers>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
Ballinger answered 21/5 at 11:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.