XML-FO : how to re-use graphics?

72 views Asked by At

I'm adding an SVG logo to every page of a document and notice that the logo gets "inlined" on every page, rather than appearing only once in the PDF file and then referenced when used on each page.

This means that the PDF file becomes much bigger than it needs to be. Here's what I do:

<?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:afp="http://xmlgraphics.apache.org/fop/extensions/afp"      
      >
    <xsl:output method="xml" indent="yes"/>
    <xsl:template match="/">
        <fo:root>
            <fo:layout-master-set>
                <fo:simple-page-master master-name="A4-portrait"
                        page-height="29.7cm" page-width="21.0cm" 
                        margin-top="5mm"  margin-bottom="5mm"
                        margin-left="1.0in" margin-right="1.0in">
                    <fo:region-body margin-top="3cm"/>
                    <fo:region-before extent="10mm"/>  
                </fo:simple-page-master>
            </fo:layout-master-set>

            <fo:page-sequence master-reference="A4-portrait" 
                            initial-page-number="1" 
                            force-page-count="no-force">


                <!-- header -->
                <fo:static-content flow-name="xsl-region-before">
                    <fo:block text-align="end" >
                        <fo:external-graphic  
                            src="../mylogo.svg"/>
                    </fo:block>
                </fo:static-content>

                <!-- content -->
                <fo:flow flow-name="xsl-region-body">
                    <!-- a simple 2 page document -->
                    <fo:block page-break-before="always"> X </fo:block>
                    <fo:block page-break-before="always"> X </fo:block>

                </fo:flow>
            </fo:page-sequence>
        </fo:root>
    </xsl:template>
</xsl:stylesheet>

As can be seen there's only a single character on each page. If I from the above generate a 2 page PDF document it will be 13.01 KB and if I generate a 48 page document it will be 206.56 KB. I would have expected the two PDF document to be almost the same size.

How can I achieve that the logo is re-used and referenced instead of inlined ? Not using vector graphics is not an option for me.

Apache FOP 2.1, Java 8.

Update

I've found this which is somewhat similar. As far as I can tell the problem in that question is that the contents of the header seems to be inlined on every page (thus ballooning the PDF size), somewhat similar to my problem.

0

There are 0 answers