Search code examples
javasvgapache-fop

Apache FOP 2.0 - Why is no ImagePreloader found for SVG?


I am using Apache FOP 2.0 in a jsf application (with JBoss 7) to create pdf files. But I get the following error if I want to include a svg:

Image not available. URI: image/svg.svg. Reason: org.apache.xmlgraphics.image.loader.ImageException: The file format is not supported. No ImagePreloader found for image/svg.svg (No context info available): org.apache.xmlgraphics.image.loader.ImageException: The file format is not supported. No ImagePreloader found for image/svg.svg

The error only occur with svg files. Other image types (jpg or png) work correctly. So I did some research and found some approaches:


Apache FOP in a Java Applet - No ImagePreloader found for data

I changed my pom so xmlgraphics-commons is loaded before fop, but it did not work. I am using xmlgraphics-commons in version 2.0.1 batik in version 1.8 and avalon-framework (api and impl) in version 4.3.1.


http://apache-fop.1065347.n5.nabble.com/FOP-1-0-images-fail-to-render-td7348.html

My last approache was to use the hints from the last post (from morjane), but it did not solved my problem.


Some have problems with barcode libraries but I am not using one.

If anyone can give me a hint or has an idea how to solve this error I would be very grateful. Please ask if more information are needed. Thanks in advance.


Solution

  • Adding xercesImpl to my pom fixed the problem.

    <dependency>
       <groupId>xerces</groupId>
       <artifactId>xercesImpl</artifactId>
       <version>2.11.0</version>
    </dependency>
    

    It also fixed the following error I had using batik for .svg to .eps conversion:

    org.apache.batik.transcoder.TranscoderException: null Enclosed Exception: SAX2 driver class org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser not found.