4

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

Oomph Fortuity
  • 5,710
  • 10
  • 44
  • 89

3 Answers3

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>
Vincent Biragnet
  • 2,950
  • 15
  • 22
  • 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. – Gernot Feb 02 '23 at 10:44
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

Community
  • 1
  • 1
Oomph Fortuity
  • 5,710
  • 10
  • 44
  • 89
0

The equivalent solution for gradle would be:

shadowJar{
    mergeServiceFiles()
}
Iikka
  • 49
  • 2