使用recto和verso页面从docbook(来自asciidoc)创建pdf

时间:2013-10-11 07:47:10

标签: xslt pdf docbook asciidoc

我想创建一篇文章,其标题页包含标题和subtile,第二页包含标题,法律声明和版权,第三页包含toc。

我在asciidoc中写入,然后转换为docbook,然后使用xsltproc和fop生成pdf。全部在centos 6.4系统上。据我所知,我必须创建一个自定义titlepage xsl文件来实现我想要的。我跟着doccookbook创建了我的xsl。但不知怎的,这根本不适用,我根本没有单独的标题页。

我的asciidoc myreport.txt是

    My super duper report
    =====================
    :toc:

    My subtitle

    //copyright notice
     +
    by acme

    Publication date 102013 +
    Copyright (c) 2013 acme

    Permission to use, copy, modify and distribute this report and its accompanying
    documentation for any purpose and without fee is hereby granted in perpetuity,
    provided that the above copyright notice and this paragraph appear in all copies.

    First Chapter
    -------------
    bla bla

    Second Chapter
    --------------
    tables and foo bar

然后我创建了我的xml标题页模板articletitlepage.xml

<!DOCTYPE t:templates [
<!ENTITY hsize0 "10pt">
<!ENTITY hsize1 "12pt">
<!ENTITY hsize2 "14.4pt">
<!ENTITY hsize3 "17.28pt">
<!ENTITY hsize4 "20.736pt">
<!ENTITY hsize5 "24.8832pt">
<!ENTITY hsize0space "7.5pt"> <!-- 0.75 * hsize0 -->
<!ENTITY hsize1space "9pt"> <!-- 0.75 * hsize1 -->
<!ENTITY hsize2space "10.8pt"> <!-- 0.75 * hsize2 -->
<!ENTITY hsize3space "12.96pt"> <!-- 0.75 * hsize3 -->
<!ENTITY hsize4space "15.552pt"> <!-- 0.75 * hsize4 -->
<!ENTITY hsize5space "18.6624pt"> <!-- 0.75 * hsize5 -->
]>
<t:templates xmlns:t="http://nwalsh.com/docbook/xsl/template/1.0"
             xmlns:param="http://nwalsh.com/docbook/xsl/template/1.0/param"
             xmlns:fo="http://www.w3.org/1999/XSL/Format"
             xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<!-- ==================================================================== -->

<t:titlepage t:element="article" t:wrapper="fo:block"
             font-family="{$title.fontset}">
<!-- ==================================================================== -->
  <t:titlepage-content t:side="recto"
             start-indent="0pt"
             text-align="center">

    <title t:named-template="component.title"
           param:node="ancestor-or-self::article[1]"
           keep-with-next.within-column="always"
           font-size="&hsize5;"
           font-weight="bold"/>

    <subtitle/>

  </t:titlepage-content>

<!-- ==================================================================== -->
  <t:titlepage-content t:side="verso">
    <title t:named-template="component.title" 
           param:node="ancestor-or-self::article[1]"
           keep-with-next.within-column="always"
           font-size="&hsize2;"
           font-weight="bold"/>
    <copyright space-before="0.5em"/>
    <legalnotice text-align="start"
                 margin-left="0.5in"
                 margin-right="0.5in"
                 font-family="{$body.fontset}"/>

  </t:titlepage-content>

  <t:titlepage-separator>
  </t:titlepage-separator>

  <t:titlepage-before t:side="recto">
    </t:titlepage-before>

  <t:titlepage-before t:side="verso">
    </t:titlepage-before>

</t:titlepage>


<!-- ==================================================================== -->

</t:templates>

我用

将其翻译成xsl
xsltproc --output articletitlepage.xsl  /usr/share/sgml/docbook/xsl-stylesheets-1.75.2/template/titlepage.xsl articletitlepage.xml;

然后我创建myarticletitlepage.xsl为

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
  xmlns:fo="http://www.w3.org/1999/XSL/Format"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:import href="/etc/asciidoc/docbook-xsl/fo.xsl"/>
  <xsl:import href="articletitlepage.xsl"/>
</xsl:stylesheet>

然后我发出

xsltproc  --stringparam callout.graphics 0         --stringparam navig.graphics 0         --stringparam admon.textlabel 1         --stringparam admon.graphics 0 --nonet         "/home/isaac/code/testing/myarticletitlepage.xsl" "./myreport.xml" >"./myreport.fo"
fop  -fo "./myreport.fo" -pdf "./myreport.pdf"

这会生成一个pdf,其标题是两次不同的字体大小(所以我的标题页模板生效了)。但这一切都在一页上。我知道,对于版权和法律问题,我在asciidoc中遗漏了一些东西(欢迎提示),但是现在如果我能得到正面和反面的单独页面,我会非常感激。

0 个答案:

没有答案