Search code examples
javaapache-fop

Apache FOP fox:external-document not working when using PDF file


I am trying to append an pdf document using Apache FOP fox:external-document, but it is throwing the following exception when using pdf type:

SEVERE: Image not available. URI: /pathToPdf/file.pdf. Reason: org.apache.xmlgraphics.image.loader.ImageException: The file format is not supported. No ImagePreloader found for /pathToPdf/file.pdf (See position 202:89)
org.apache.xmlgraphics.image.loader.ImageException: The file format is not supported. No ImagePreloader found for /pathToPdf/file.pdf
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:fox="http://xmlgraphics.apache.org/fop/extensions">
    <xsl:template match="/">
        <fo:root>
            <fo:layout-master-set>
                ...
            </fo:layout-master-set>            

            <fox:external-document content-type="pdf" src="/pathToPdf/file.pdf"/>
        </fo:root>
    </xsl:template>
</xsl:stylesheet>

I am using Apache FOP 2.3 and Java 8


Solution

  • The extension property fox:external-document is originally meant to insert images as pages in the pdf output.

    In order to use it with pdf files too you need the PDF Images Plug-In.

    Just download and put (or link) the jar in the lib folder and everything should work as you expected.