O'Reilly logo

SVG Essentials by J. David Eisenberg

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Embedding SVG in XSL Formatting Objects

The other XML application that supports inline SVG is Extensible Stylesheet Language Formatting Objects (XSL-FO). This is a markup language used to specify page formatting of text. You may use the Apache Software Foundation’s FOP software tool to take a document written in XSL-FO and transform it to Adobe’s PDF (Portable Document Format). You may see the XSL-FO specification at http://www.w3.org/TR/xsl/ or read a brief introduction in Chapter 13 of XML in a Nutshell by Elliotte Rusty Harold and W. Scott Means. FOP is available at http://xml.apache.org.

Example F-2 lays out a document with text and SVG graphics for the cover of what must surely be one of the more eccentric Compact Discs ever recorded. The graphic has nothing whatsoever to do with the subject of the disc; it’s merely an existence proof.

Once we run this file through FOP, we can display it in our favorite PDF viewer. Figure F-1 shows a screenshot.

PDF output

Figure F-1. PDF output

Example F-2. Combined XSL-FO and SVG markup

<?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">     [1]
<fo:layout-master-set>     [2]
<fo:simple-page-master     [3]
    margin-right="0.5cm"
    margin-left="0.5cm"
    margin-bottom="0.5cm"
    margin-top="0.5cm"
    page-height="12cm" page-width="12cm"
    master-name="cdcover">
<fo:region-body/>     [4] </fo:simple-page-master> </fo:layout-master-set> <fo:page-sequence ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required