Home > Uncategorized > Docbook to PDF (2)

Docbook to PDF (2)

This is the sequel of this post. I finally managed to make it works with FOP and Saxon. Here is how to setup things on Debian Sid:

#Docbook XSL 1.75 doesn't support inline SVG, 1.76 does, so we use the Debian experimental version
sudo apt-get install -t experimental docbook-xsl-ns fop
#jeuclid is required to transform MathML
sudo apt-get install docbook-xsl-saxon libjeuclid-fop-java
echo 'FOP_HYPHENATION_PATH="jeuclid-fop jeuclid-core"' > ~/.foprc

Then to process a file:

#Support for XInclude
saxonxslt=$(cat <<EOF
java -cp /usr/share/java/saxon.jar:/usr/share/java/xercesImpl.jar 
  -Djavax.xml.parsers.DocumentBuilderFactory=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl 
  -Djavax.xml.parsers.SAXParserFactory=org.apache.xerces.jaxp.SAXParserFactoryImpl 
  -Dorg.apache.xerces.xni.parser.XMLParserConfiguration=org.apache.xerces.parsers.XIncludeParserConfiguration 
  com.icl.saxon.StyleSheet
EOF
)
#XSL Transformation
$saxonxslt -o mydocument.fo mydocument.xml /usr/share/xml/docbook/stylesheet/docbook-xsl-ns/fo/docbook.xsl paper.type=A4 draft.mode=no fop1.extensions=1
#FOP Transformation
fop mydocument.fo mydocument.pdf


Here is a sample with embedded equation and SVG:

<?xml version="1.0" encoding="UTF-8"?>
<article xmlns="http://docbook.org/ns/docbook">
  <title>Example</title>
  <sect1>
    <title>A formula</title>
    <para>
      <equation>
        <math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
          <semantics>
            <msup>
              <mfenced open="(" close=")">
                <mfrac> <mn>1</mn> <mi>e</mi> </mfrac>
              </mfenced>
              <mi>n</mi>
            </msup>
          </semantics>
        </math>
      </equation>
    </para>
  </sect1>
  <sect1>
    <title>embedded SVG</title>
    <para>
      <inlinemediaobject>
        <imageobject>
          <imagedata>
            <svg xmlns="http://www.w3.org/2000/svg">
               <circle cx="1cm" cy="2cm" r="10"/>
            </svg>
          </imagedata>
        </imageobject>
      </inlinemediaobject>
    </para>
  </sect1>
</article>

In a real life document will more probably be splitted in many files:

<?xml version="1.0" encoding="UTF-8"?>
<article xmlns="http://docbook.org/ns/docbook">
  <title>Example</title>
  <sect1>
    <title>A formula</title>
    <para>
      <equation>
        <include href="sample.mml" xmlns="http://www.w3.org/2001/XInclude" />
      </equation>
    </para>
  </sect1>
  <sect1>
    <title>embedded SVG</title>
    <para>
      <mediaobject>
        <imageobject>
          <imagedata  format="SVG" fileref="sample.svg"/>
        </imageobject>
      </mediaobject>
    </para>
  </sect1>
</article>

References:

Advertisements
Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: