You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by Phillip Oldham <ph...@activityhq.com> on 2010/07/24 02:54:03 UTC

Image not available: No ImagePreloader found

I'm using FOP 0.95, and have happily been running with a custom URIResolver class to load and embed SVG images into my PDF output.

Earlier today I changed the build process so that all the jar files that were required by FOP to be in the classpath were un-jar'd and included in my main .jar file. Since then, I've not been able to load a single image. Here is my resolver class:

    private class ImgURIResolver implements URIResolver {
	private static final String uriprefix = "img:";
	private URIResolver defaultResolver;
	protected ImgURIResolver() {}
	public ImgURIResolver(URIResolver defaultResolver) {
	    this.defaultResolver = defaultResolver;
	}
	public Source resolve(String href, String base) throws TransformerException {
	    if (href.startsWith(PREFIX)){
		    String name = href.substring(uriprefix.length());
		    try {
			for( int i = 0; i < PDFRenderer.images.size(); i++ ) {
				Image img = PDFRenderer.images.get(i);
				if( img.filename.equals(name) ) {
					return new StreamSource(new ByteArrayInputStream(img.filedata));
				    }
			    }
		    } catch (Exception e) {
			throw new TransformerException(e.getMessage());
		    }
		}
	    return defaultResolver.resolve(href, base);
	}
    }

The images are loaded into memory in another class, and I can confirm that the img.filedata is there.

The errors I see are as follows:
242405 [pool-1-thread-2] ERROR org.apache.fop.fo.FONode - Image not available: No ImagePreloader found for img:myimage.svg
242408 [pool-1-thread-2] ERROR org.apache.fop.render - Image not found: img:myimage.svg

Inline SVGs work as expected.

I'm at a loss as to what has changed... I've not removed any files, or changed anything other than the build.xml file to unjar dependencies & bundle everything into one file.

Any ideas on how I can investigate/resolve this?
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: Image not available: No ImagePreloader found

Posted by Jeremias Maerki <de...@jeremias-maerki.ch>.
On 24.07.2010 02:54:03 Phillip Oldham wrote:
> I'm using FOP 0.95, and have happily been running with a custom
> URIResolver class to load and embed SVG images into my PDF output.
> 
> Earlier today I changed the build process so that all the jar files
> that were required by FOP to be in the classpath were un-jar'd and included
> in my main .jar file.

Very bad idea IMO as you're painfully experiencing.

> Since then, I've not been able to load a single image. Here is my
> resolver class:
> 
>     private class ImgURIResolver implements URIResolver {
> 	private static final String uriprefix = "img:";
> 	private URIResolver defaultResolver;
> 	protected ImgURIResolver() {}
> 	public ImgURIResolver(URIResolver defaultResolver) {
> 	    this.defaultResolver = defaultResolver;
> 	}
> 	public Source resolve(String href, String base) throws TransformerException {
> 	    if (href.startsWith(PREFIX)){
> 		    String name = href.substring(uriprefix.length());
> 		    try {
> 			for( int i = 0; i < PDFRenderer.images.size(); i++ ) {
> 				Image img = PDFRenderer.images.get(i);
> 				if( img.filename.equals(name) ) {
> 					return new StreamSource(new ByteArrayInputStream(img.filedata));
> 				    }
> 			    }
> 		    } catch (Exception e) {
> 			throw new TransformerException(e.getMessage());
> 		    }
> 		}
> 	    return defaultResolver.resolve(href, base);
> 	}
>     }
> 
> The images are loaded into memory in another class, and I can confirm that the img.filedata is there.
> 
> The errors I see are as follows:
> 242405 [pool-1-thread-2] ERROR org.apache.fop.fo.FONode - Image not available: No ImagePreloader found for img:myimage.svg
> 242408 [pool-1-thread-2] ERROR org.apache.fop.render - Image not found: img:myimage.svg
> 
> Inline SVGs work as expected.
> 
> I'm at a loss as to what has changed... I've not removed any files, or
> changed anything other than the build.xml file to unjar dependencies &
> bundle everything into one file.
> 
> Any ideas on how I can investigate/resolve this?

The problem are the service providers under META-INF/services in FOP,
Batik and XML Graphics Commons. If you merge the JARs you also have to
merge the service provider files.

I strongly recommend not to merge JARs! You're just asking for trouble
and unnecessary work.


Jeremias Maerki


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org