Peter Schmelzer

Difficulty: ★☆☆ (easy)
Keywords: title page, cover, graphic, block, format

Problem

You need to know how to insert a graphic to your titlepage.

Solution

To insert a graphic to one of your title pages, you need to create a template for titlepages as described in Section 4.2, “Designing a Title Page”.

To add your graphic, the XSL-FO specification has defined an fo:block-container to encapsulate an fo:external-graphics element. Additionally, there are many, many options to modify your graphic on the title pages like scaling or positioning. The following listing show how to use both elements.

<fo:block space-before="1em" space-after="1em">
    <fo:external-graphic src="{$img.src.path}/your-graphic.svg"/>
</fo:block>

Depending on the position within the customized title element, where you want to place your graphic, you must place the fo:block-container before or after the title block-container.

The following example places the graphic after the document title. The graphic is scaled by 50% and the aspect ratio is preserved.

<xsl:template match="d:title" mode="book.titlepage.recto.auto.mode">
    <fo:block xmlns:fo="http://www.w3.org/1999/XSL/Format"
        xsl:use-attribute-sets="book.titlepage.recto.style" text-align="center"
        font-size="32pt" space-before="18.6624pt" font-weight="bold">
        <xsl:call-template name="division.title">
            <xsl:with-param name="node" select="ancestor-or-self::d:book[1]"/>
        </xsl:call-template>
        <fo:block space-before="1em" space-after="1em">
            <fo:external-graphic src="{$img.src.path}/your-graphic.svg" content-height="50%"
                scaling="uniform"/>
         </fo:block>
    </fo:block>
</xsl:template>

Discussion

It's a good idea to use only supported high resolution bitmap graphics (300x300 dpi) or supported vector graphics for your title page. Otherwise you may notice that your graphic looks like small blocks.

Note

Your graphic is placed between the left and right margins of your title page. Depending on the graphic size, the graphic will be scaled up or down automatically.

See Also


Project@GitHubIssue#9