Search code examples
apache-fop

Apache FOP / custom image does not show in PDF


With FOP 2.6 I try to convert an FO file to a PDF. I use the standard configuration file on Windows.

As one image format is not supported, I created a custom PreLoader, ImageLoaderFactory and ImageConverter. They are registered via service entries and from the logs I can see they are beeing used:

DEBUG: Chosen pipeline: Loader: org.apache.xmlgraphics.image.loader.impl.ImageLoaderRaw@2dad1d4c Converters: [image.loader.custom.ImageConverterCustom2PNG@26080b64]
DEBUG: Creating new Source for figure\sb.custom
DEBUG: convert custom image: org.apache.xmlgraphics.image.loader.impl.ImageRawStream: figure\sb.custom (image/custom)
DEBUG: custom image converted to png
DEBUG: Image is made cacheable: figure\sb.custom (image/custom)
DEBUG: New ImageAdapter created for key: figure\sb.custom
INFO: Rendered page #86.

But the image does not show up in the generated PDF file...

The converter converts the custom format to PNG and returns RAW_PNG:

ByteArrayInputStream convertedStream = new ByteArrayInputStream(outBuffer.toByteArray());
PNGFile pngFile = new PNGFile(convertedStream, originalInfo.getOriginalURI());
ImageRawPNG image = pngFile.getImageRawPNG(originalInfo);

I have also tried to convert to JPG also with no success.

Using the converted file directly does work: Instead of:

<fo:external-graphic src="url(figure\sb.custom)" width="auto" height="auto" content-width="160mm" content-height="auto"/>

This:

<fo:external-graphic src="url(custom.png)" width="auto" height="auto" content-width="160mm" content-height="auto"/>

Shows the image.

Are the converters not being chained? Or do I miss something crucial?


Solution

  • I finally found the root cause. My image preloader was missing these lines when createing the image size:

    size.setResolution(context.getSourceResolution());
    size.calcSizeFromPixels();