Search code examples
apache-fopasciidoca2x

Option for using scale-down-to-fit with a2x and FOP


I'm doing a build system for a documentation project and I need help trying to limit the width of images when generating PDF output.

I'm using a2x --fop to generate the PDF output which works fine, but I need the scale-down-to-fit option (Scale down to fit an image in FOP) enabled for all images.

How can I enable this while using a2x --fop?


Solution

  • Remarkably, I managed to sort this out even though XSL(T) is all smoke and mirrors to me!

    To enable this, I managed to get an XSL example from http://www.renderx.com/usecasestest.html and example the XML produced by a2x to craft the following snippet which I've currently added to the default fo.xsl included with asciidoc/a2x:

    <xsl:template match="imagedata">
        <fo:block line-height="1pt">
            <fo:external-graphic content-width="scale-down-to-fit" content-height="100%" width="100%" scaling="uniform">
                <xsl:attribute name="src">
                    url(
                    <xsl:value-of select="@fileref"/>
                    )
                </xsl:attribute>
            </fo:external-graphic>
        </fo:block>
    </xsl:template>