最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【记录】docbook 5.0的折腾过程

Docbook crifan 2567浏览 0评论

1.去Cygwin主页中下载了setup.exe,然后在线下载,选的是163的源。因为我看到第一个源就是163的,所以猜测现在最新版本的cygwin,都可以根据镜像服务器的速度快慢,而自动把速度快的放在前面了。然后就是选择安装的项,下载安装,速度蛮快的,1MB/s左右的速度。

记得要在安装的时候,选上对应的xsltproc工具,libxml2等库(好像是在lib大项下面,找不到没关系,那个界面是可以搜索到的)。

2.想要去参考:一个简单的Docbook 5.0例子,去下载xsltproc,找到windows下面的二进制版本的下载地方

Win32 binaries (HTTP)

Win32 binaries (FTP)

结果,却发现上述两个地址,都无法打开。其中http的地址,好像不可用了。ftp的地址,此处我这里被限制了。

所以打算去下载源码,在cygwin下载编译一下。

3.突然发现,原来cygwin下面,已经带了xsltproc了:

CLi@PC-CLI-1 ~
$ xsltproc.exe
Usage: xsltproc [options] stylesheet file [file ...]
   Options:
        --version or -V: show the version of libxml and libxslt used
        --verbose or -v: show logs of what's happening
        --output file or -o file: save to a given file
        --timing: display the time used
        --repeat: run the transformation 20 times
        --debug: dump the tree of the result instead
        --dumpextensions: dump the registered extension elements and functions to stdout
        --novalid skip the Dtd loading phase
        --nodtdattr do not default attributes from the DTD
        --noout: do not dump the result
        --maxdepth val : increase the maximum depth
        --maxparserdepth val : increase the maximum parser depth
        --html: the input document is(are) an HTML file(s)
        --encoding: the input document character encoding
        --param name value : pass a (parameter,value) pair
               value is an UTF8 XPath expression.
               string values must be quoted like "'string'"
 or            use stringparam to avoid it
        --stringparam name value : pass a (parameter, UTF8 string value) pair
        --path 'paths': provide a set of paths for resources
        --nonet : refuse to fetch DTDs or entities over network
        --nowrite : refuse to write to any file or resource
        --nomkdir : refuse to create directories
        --writesubtree path : allow file write only with the path subtree
        --catalogs : use SGML catalogs from $SGML_CATALOG_FILES
                     otherwise XML Catalogs starting from
                 file:///etc/xml/catalog are activated by default
        --xinclude : do XInclude processing on document input
        --xincludestyle : do XInclude processing on stylesheets
        --load-trace : print trace of all external entites loaded
        --profile or --norman : dump profiling informations

Project libxslt home page: http://xmlsoft.org/XSLT/
To report bugs and get help: http://xmlsoft.org/XSLT/bugs.html




CLi@PC-CLI-1 ~
$ xsltproc.exe  -V
Using libxml 20708, libxslt 10126 and libexslt 815
xsltproc was compiled against libxml 20708, libxslt 10126 and libexslt 815
libxslt 10126 was compiled against libxml 20708
libexslt 815 was compiled against libxml 20708

所以,貌似可以直接用了,就不用下载源码自己去编译了。

然后对于iconv,也已经有了:

CLi@PC-CLI-1 ~
$ iconv.exe --help
Usage: iconv [OPTION...] [-f ENCODING] [-t ENCODING] [INPUTFILE...]
or:    iconv -l

Converts text from one encoding to another encoding.

Options controlling the input and output format:
  -f ENCODING, --from-code=ENCODING
                              the encoding of the input
  -t ENCODING, --to-code=ENCODING
                              the encoding of the output

Options controlling conversion problems:
  -c                          discard unconvertible characters
  --unicode-subst=FORMATSTRING
                              substitution for unconvertible Unicode characters
  --byte-subst=FORMATSTRING   substitution for unconvertible bytes
  --widechar-subst=FORMATSTRING
                              substitution for unconvertible wide characters

Options controlling error output:
  -s, --silent                suppress error messages about conversion problems

Informative output:
  -l, --list                  list the supported encodings
  --help                      display this help and exit
  --version                   output version information and exit

Report bugs to <[email protected]>.

CLi@PC-CLI-1 ~
$ iconv.exe --version
iconv (GNU libiconv 1.14)
Copyright (C) 2000-2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Bruno Haible.

其他几个相关工具或库,zlib,libxslt,libxml2,记得安装cygwin的时候,也已经都选了。

4.去Docbook XSL转换样式表下载样式转换表docbook-xsl-ns。下载后,放到我的cygwin下面的目录中了:

 

CLi@PC-CLI-1 ~/develop/docbook/tools/docbook-xsl-ns-1.76.1
$ pwd
/home/CLi/develop/docbook/tools/docbook-xsl-ns-1.76.1

CLi@PC-CLI-1 ~/develop/docbook/tools/docbook-xsl-ns-1.76.1
$ ls
AUTHORS      docsrc      highlighting  install.sh  NEWS       README              roundtrip  tools    xhtml-1_1
BUGS         eclipse     html          javahelp    NEWS.html  RELEASE-NOTES.html  slides     VERSION
catalog.xml  epub        htmlhelp      lib         NEWS.xml   RELEASE-NOTES.pdf   template   webhelp
common       extensions  images        Makefile    params     RELEASE-NOTES.txt   tests      website
COPYING      fo          INSTALL       manpages    profiling  RELEASE-NOTES.xml   TODO       xhtml
 

然后就照葫芦画瓢,将下面内容:

<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version='1.0'>
<xsl:include href="/home/CLi/develop/docbook/tools/docbook-xsl-ns-1.76.1/html/docbook.xsl"/>
<xsl:output method="html"
            encoding="UTF-8"
            indent="no"/>
</xsl:stylesheet> 
 

另存为docbook_crl.xsl文件,放在了和docbook.xsl同一目录:

/home/CLi/develop/docbook/tools/docbook-xsl-ns-1.76.1/html

下面。

然后把下面内容:

<?xml version='1.0' encoding="utf-8"?>
<article xmlns="http://docbook.org/ns/docbook" version="5.0" xml:lang="zh-CN"
  xmlns:xlink='http://www.w3.org/1999/xlink'>
  <articleinfo>
    <title>我的第一篇Docbook 5.0文档</title>
    <author>
      <firstname>Crifan</firstname>

      <surname>Li</surname>
    </author>
  </articleinfo> 

  <section>
    <title>文档介绍</title>

    <para>
      这是我的第一篇Docbook 5.0文档,欢迎你来到<link xlink:href='https://www.crifan.com'>Crifan的博客</link>。
    </para>
  </section>
</article> 

保存为cnBookTest.xml文件。

然后去试着运行xsltproc,结果出错:

CLi@PC-CLI-1 ~/develop/docbook/written/test
$ ls
cnBookTest.xml

CLi@PC-CLI-1 ~/develop/docbook/written/test
$ xsltproc -o cnBookTest.html docbook_crl.xsl cnBookTest.xml
warning: failed to load external entity "docbook_crl.xsl"
cannot parse docbook_crl.xsl

然后折腾了一会,知道了原因,是没有指定正确路径,导致找不到对应的xsl文件,所以先暂时写了绝对路径,就可以了:

CLi@PC-CLI-1 ~/develop/docbook/written/test
$ xsltproc -o cnBookTest.html /home/CLi/develop/docbook/tools/docbook-xsl-ns-1.76.1/html/docbook_crl.xsl cnBookTest.xml

然后就没有任何异常的执行成功了,生成的html效果如下:

docbook 5.0 html

5.继续参考:使用Apache FOP将Docbook文档转换成PDF,找到FOP官网中的的FOP二进制下载地址,下载了二进制的1.0版本的fop,解压后,放到了cygwin下面,但是运行fop出错说是JAVA_HOME没找到:

CLi@PC-CLI-1 ~/develop/docbook/tools/fop
$ pwd
/home/CLi/develop/docbook/tools/fop

CLi@PC-CLI-1 ~/develop/docbook/tools/fop
$ ls -l
total 209
drwxr-xr-x+ 1 Administrators Domänen-Benutzer     0 Apr 26 12:36 build
drwxr-xr-x+ 1 Administrators Domänen-Benutzer     0 Apr 26 12:36 conf
drwxr-xr-x+ 1 Administrators Domänen-Benutzer     0 Apr 26 12:36 docs
drwxr-xr-x+ 1 Administrators Domänen-Benutzer     0 Apr 26 12:35 examples
-rwxr-xr-x  1 Administrators Domänen-Benutzer  7422 Jul 13  2010 fop
-rwxr-xr-x  1 Administrators Domänen-Benutzer  4082 Jul 13  2010 fop.bat
-rwxr-xr-x  1 Administrators Domänen-Benutzer  3191 Jul 13  2010 fop.cmd
-rwxr-xr-x  1 Administrators Domänen-Benutzer 10844 Jul 13  2010 fop.js
drwxr-xr-x+ 1 Administrators Domänen-Benutzer     0 Apr 26 12:36 javadocs
-rwxr-xr-x  1 Administrators Domänen-Benutzer 13662 Jul 13  2010 KEYS
drwxr-xr-x+ 1 Administrators Domänen-Benutzer     0 Apr 26 12:36 lib
-rwxr-xr-x  1 Administrators Domänen-Benutzer 11358 Jul 13  2010 LICENSE
-rwxr-xr-x  1 Administrators Domänen-Benutzer   351 Jul 13  2010 NOTICE
-rwxr-xr-x  1 Administrators Domänen-Benutzer  9729 Jul 13  2010 README
-rwxr-xr-x  1 Administrators Domänen-Benutzer 97666 Jul 13  2010 status.xml

CLi@PC-CLI-1 ~/develop/docbook/tools/fop
$ ./fop
Error: JAVA_HOME is not defined correctly.
  We cannot execute java

然后试了下,发现Cygwin下面没安装java。

所以再回去重新安装Cygwin中的java。

6.在Cygwin中找了半天,也没找到所需要的java,只找到其他一些和java有关的:

cygwin no java

后来,想到了,估计是需要去安装windows下面的java的才可以。

但是又觉得很诡异,记得之前版本的cygwin,好像是带了java的。

先不管,去安装windows下面的java再说。

安装了最新的版本的windows的java:jre-6u31-windows-i586-iftw.exe,安装后,就可以在Cygwin下面自动找到java了:

CLi@PC-CLI-1 ~/develop/docbook/tools/fop
$ java
Usage: java [-options] class [args...]
           (to execute a class)
   or  java [-options] -jar jarfile [args...]
           (to execute a jar file)

where options include:
    -client       to select the "client" VM
    -server       to select the "server" VM
    -hotspot      is a synonym for the "client" VM  [deprecated]
                  The default VM is client.

    -cp <class search path of directories and zip/jar files>
    -classpath <class search path of directories and zip/jar files>
                  A ; separated list of directories, JAR archives,
                  and ZIP archives to search for class files.
    -D<name>=<value>
                  set a system property
    -verbose[:class|gc|jni]
                  enable verbose output
    -version      print product version and exit
    -version:<value>
                  require the specified version to run
    -showversion  print product version and continue
    -jre-restrict-search | -jre-no-restrict-search
                  include/exclude user private JREs in the version search
    -? -help      print this help message
    -X            print help on non-standard options
    -ea[:<packagename>...|:<classname>]
    -enableassertions[:<packagename>...|:<classname>]
                  enable assertions
    -da[:<packagename>...|:<classname>]
    -disableassertions[:<packagename>...|:<classname>]
                  disable assertions
    -esa | -enablesystemassertions
                  enable system assertions
    -dsa | -disablesystemassertions
                  disable system assertions
    -agentlib:<libname>[=<options>]
                  load native agent library <libname>, e.g. -agentlib:hprof
                    see also, -agentlib:jdwp=help and -agentlib:hprof=help
    -agentpath:<pathname>[=<options>]
                  load native agent library by full pathname
    -javaagent:<jarpath>[=<options>]
                  load Java programming language agent, see java.lang.instrument
    -splash:<imagepath>
                  show splash screen with specified image

CLi@PC-CLI-1 ~/develop/docbook/tools/fop
$ java -version
java version "1.6.0_31"
Java(TM) SE Runtime Environment (build 1.6.0_31-b05)
Java HotSpot(TM) Client VM (build 20.6-b01, mixed mode)

然后fop也就可以运行了:

CLi@PC-CLI-1 ~/develop/docbook/tools/fop
$ ./fop
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xmlgraphics/image/loader/ImageContext
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClassCond(Unknown Source)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at java.security.SecureClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.access$000(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at org.apache.fop.cli.CommandLineOptions.<init>(CommandLineOptions.java:121)
        at org.apache.fop.cli.Main.startFOP(Main.java:157)
        at org.apache.fop.cli.Main.main(Main.java:205)
Caused by: java.lang.ClassNotFoundException: org.apache.xmlgraphics.image.loader.ImageContext
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 15 more

7.想要再去添加对应的fop的配置,但是发现,我这里没有那个fop-ttfreader。

后来网上找了:

中文docbook转换成PDF终于实现

以及我之前的帖子:

【记录】DocBook开发过程 – 2

发现是可以用java来生成对应的font的xml文件的。

然后就去Cygwin下面试试:

CLi@PC-CLI-1 ~/develop/docbook/tools/fop
$ java -cp build/fop.jar:lib/avalon-framework-4.2.0.jar:lib/commons-logging-1.0.4.jar:lib/commons-io-1.3.1.jar:lib/xmlgraphics-commons-1.4.jar org.apache.fop.fonts.apps.TTFReader -ttcname SimSun /cygdrive/c/WINDOWS/Fonts/simsun.ttc fonts/simsun.xml
java.lang.NoClassDefFoundError: org/apache/fop/fonts/apps/TTFReader
Caused by: java.lang.ClassNotFoundException: org.apache.fop.fonts.apps.TTFReader
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: org.apache.fop.fonts.apps.TTFReader.  Program will exit.
Exception in thread "main"

上述错误的结果,和之前遇到的是一样的,后来是根据:

【记录】DocBook开发过程 – 2

中的方法,换到windows下面执行,就可以了。

所以现在也去windows的cmd下面执行试试。

然后又出错了:

D:\tmp\tmp_dev_root\cgwin\home\CLi\develop\docbook\tools\fop>java -cp build/fop.jar:lib/avalon-framework-4.2.0.jar:lib/commons-logging-1.0.4.jar:lib/commons-io-1.3.1.jar:lib/xmlgraphics-commons-1.4.jar org.apache.fop.fon
ts.apps.TTFReader -ttcname SimSun /cygdrive/c/WINDOWS/Fonts/simsun.ttc fonts/simsun.xml
'java' is not recognized as an internal or external command,
operable program or batch file.

所以又去在环境变量中添加对应的java路径:

给PATH环境变量中添加java的的bin路径:

C:\Program Files (x86)\Java\jre6\bin

然后就可以执行了,但是出现同样错误:

D:\tmp\tmp_dev_root\cgwin\home\CLi\develop\docbook\tools\fop>java -cp build/fop.jar:lib/avalon-framework-4.2.0.jar:lib/commons-logging-1.0.4.jar:lib/commons-io-1.3.1.jar:lib/xmlgraphics-commons-1.4.jar org.apache.fop.fon
ts.apps.TTFReader -ttcname SimSun /cygdrive/c/WINDOWS/Fonts/simsun.ttc fonts/simsun.xml
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/fop/fonts/apps/TTFReader
Caused by: java.lang.ClassNotFoundException: org.apache.fop.fonts.apps.TTFReader
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: org.apache.fop.fonts.apps.TTFReader.  Program will exit.

看来还是不行啊。

后来添加了环境变量:

CLASSPATH=.;%JAVA_HOME%\lib\;

也还是不行。

后来发现是命令搞错了,换成这样的,就可以了:

D:\tmp\tmp_dev_root\cgwin\home\CLi\develop\docbook\tools\fop>java -cp build\fop.jar;lib\avalon-framework-4.2.0.jar;lib\commons-logging-1.0.4.jar;lib\commons-io-1.3.1.jar;lib\xmlgraphics-commons-1.4.jar org.apache.fop.fon
ts.apps.TTFReader -ttcname SimSun c:\WINDOWS\Fonts\simsun.ttc fonts\simsun.xml
TTF Reader for Apache FOP 1.0

Parsing font...
Reading c:\WINDOWS\Fonts\simsun.ttc...
This is a TrueType collection file with 2 fonts
Containing the following fonts:
SimSun <-- selected
NSimSun
Font Family: [??, SimSun]
Creating xml font file...
Creating CID encoded metrics...
Writing xml font file fonts\simsun.xml...
Error while building XML font metrics file.
javax.xml.transform.TransformerException: Error writing the output file

不过上面是由于没在fop下面建立fonts文件夹而导致输出有问题,所有建立了fonts文件夹后,再执行,就可以了:

D:\tmp\tmp_dev_root\cgwin\home\CLi\develop\docbook\tools\fop>java -cp build\fop.jar;lib\avalon-framework-4.2.0.jar;lib\commons-logging-1.0.4.jar;lib\commons-io-1.3.1.jar;lib\xmlgraphics-commons-1.4.jar org.apache.fop.fon
ts.apps.TTFReader -ttcname SimSun c:\WINDOWS\Fonts\simsun.ttc fonts\simsun.xml
TTF Reader for Apache FOP 1.0

Parsing font...
Reading c:\WINDOWS\Fonts\simsun.ttc...
This is a TrueType collection file with 2 fonts
Containing the following fonts:
SimSun <-- selected
NSimSun
Font Family: [??, SimSun]
Creating xml font file...
Creating CID encoded metrics...
Writing xml font file fonts\simsun.xml...
This font contains no embedding license restrictions.

XML font metrics file successfully created.

然后再用同样方法,生成simhei字体:(注。当前win7,没有simhei.ttc而有simhei.ttf。所以才用simhei.ttf。)

D:\tmp\tmp_dev_root\cgwin\home\CLi\develop\docbook\tools\fop>java -cp build\fop.jar;lib\avalon-framework-4.2.0.jar;lib\commons-logging-1.0.4.jar;lib\commons-io-1.3.1.jar;lib\xmlgraphics-commons-1.4.jar org.apache.fop.fon
ts.apps.TTFReader -ttcname SimHei c:\WINDOWS\Fonts\simhei.ttc fonts\simhei.xml
TTF Reader for Apache FOP 1.0

Parsing font...
Reading c:\WINDOWS\Fonts\simhei.ttc...
Error while building XML font metrics file.
java.io.FileNotFoundException: c:\WINDOWS\Fonts\simhei.ttc (The system cannot find the file specified)


D:\tmp\tmp_dev_root\cgwin\home\CLi\develop\docbook\tools\fop>java -cp build\fop.jar;lib\avalon-framework-4.2.0.jar;lib\commons-logging-1.0.4.jar;lib\commons-io-1.3.1.jar;lib\xmlgraphics-commons-1.4.jar org.apache.fop.fon
ts.apps.TTFReader -ttcname SimHei c:\WINDOWS\Fonts\simhei.ttf fonts\simhei.xml
TTF Reader for Apache FOP 1.0

Parsing font...
Reading c:\WINDOWS\Fonts\simhei.ttf...
Font Family: [??, SimHei]
Creating xml font file...
Creating CID encoded metrics...
Writing xml font file fonts\simhei.xml...
This font contains no embedding license restrictions.

XML font metrics file successfully created.

8.将上述两个字体xml文件simhei.xml和simsun.xml,以及fop\conf下面的fop.xconf,都拷贝到/etc/fop下面。

然后给fop.xconf中添加了对应的font配置:

        <font metrics-url="file:///etc/fop/simsun.xml" kerning="yes" embed-url="file:///usr/local/share/fonts/msfonts/simsun.ttc">
          <font-triplet name="SimSun" style="normal" weight="normal"/>
          <font-triplet name="SimSun" style="normal" weight="bold"/>

          <font-triplet name="SimSun" style="italic" weight="normal"/>
          <font-triplet name="SimSun" style="italic" weight="bold"/>
        </font>

        <font metrics-url="file:///etc/fop/simhei.xml" kerning="yes" embed-url="file:///usr/local/share/fonts/msfonts/simhei.ttf">
          <font-triplet name="SimHei" style="normal" weight="normal"/>
          <font-triplet name="SimHei" style="normal" weight="bold"/>

          <font-triplet name="SimHei" style="italic" weight="normal"/>
          <font-triplet name="SimHei" style="italic" weight="bold"/>
        </font>

        <directory recursive="true">/usr/share/fonts/</directory>
        <auto-detect/>

同时,也去把对应的C:\Windows\Fonts中的simhei.ttf和simsun.ttc,拷贝到在/usr/share/fonts下新建的文件夹msfonts中去。

9.然后将如下内容保存为docbook_fo.xsl:

<?xml version='1.0'?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:exsl="http://exslt.org/common"
                xmlns:fo="http://www.w3.org/1999/XSL/Format"
                xmlns:ng="http://docbook.org/docbook-ng"
                xmlns:db="http://docbook.org/ns/docbook"
                exclude-result-prefixes="db ng exsl"
                version='1.0'>

<xsl:import href="docbook.xsl"/>
<xsl:param name="body.font.family">SimSun</xsl:param>
<xsl:param name="monospace.font.family">SimSun</xsl:param>
<xsl:param name="title.font.family">SimHei</xsl:param>

</xsl:stylesheet>

然后放到

/home/CLi/develop/docbook/tools/docbook-xsl-ns-1.76.1/fo

下面,和原先的docbook.xsl同目录。

然后是可以生成了fo文件:

CLi@PC-CLI-1 ~/develop/docbook/written/test
$ xsltproc.exe -o fo/cnBookTest.fo /home/CLi/develop/docbook/tools/docbook-xsl-ns-1.76.1/fo/docbook_fo.xsl
cnBookTest.html     cnBookTest.xml      cnBookTest.xml.bak  fo/

CLi@PC-CLI-1 ~/develop/docbook/written/test
$ xsltproc.exe -o fo/cnBookTest.fo /home/CLi/develop/docbook/tools/docbook-xsl-ns-1.76.1/fo/docbook_fo.xsl cnBookTest.xml
Making portrait pages on USletter paper (8.5inx11in)

CLi@PC-CLI-1 ~/develop/docbook/written/test
$ ls fo
cnBookTest.fo

CLi@PC-CLI-1 ~/develop/docbook/written/test
$ ls fo -l
total 24
-rw-r--r-- 1 CLi Domänen-Benutzer 24105 Apr 26 14:41 cnBookTest.fo

想要去生成pdf:

CLi@PC-CLI-1 ~/develop/docbook/tools/fop
$ ./fop -c /etc/fop/fop.xconf ../../written/test/fo/cnBookTest.fo -pdf ../../written/test/output/pdf/cnBookTest.pdf
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xmlgraphics/image/loader/ImageContext
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClassCond(Unknown Source)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at java.security.SecureClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.access$000(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at org.apache.fop.cli.CommandLineOptions.<init>(CommandLineOptions.java:121)
        at org.apache.fop.cli.Main.startFOP(Main.java:157)
        at org.apache.fop.cli.Main.main(Main.java:205)
Caused by: java.lang.ClassNotFoundException: org.apache.xmlgraphics.image.loader.ImageContext
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 15 more

但是很明显,之前的fop,其实还是不能正常执行的。

先去解决这个问题再说。

10.关于如何解决fop的运行问题,折腾了一下,网上貌似没找到有效的办法。

去windows中的cmd中试了试,倒是可以执行的:

D:\tmp\tmp_dev_root\cgwin\home\CLi\develop\docbook\tools\fop>fop
FOP Version 1.0

USAGE
fop [options] [-fo|-xml] infile [-xsl file] [-awt|-pdf|-mif|-rtf|-tiff|-png|-pcl|-ps|-txt|-at [mime]|-print] <outfile>
 [OPTIONS]
  -version          print FOP version and exit
  -d                debug mode
  -x                dump configuration settings
  -q                quiet mode
  -c cfg.xml        use additional configuration file cfg.xml
  -l lang           the language to use for user information
  -r                relaxed/less strict validation (where available)
  -dpi xxx          target resolution in dots per inch (dpi) where xxx is a number
  -s                for area tree XML, down to block areas only
  -v                run in verbose mode (currently simply print FOP version and continue)

  -o [password]     PDF file will be encrypted with option owner password
  -u [password]     PDF file will be encrypted with option user password
  -noprint          PDF file will be encrypted without printing permission
  -nocopy           PDF file will be encrypted without copy content permission
  -noedit           PDF file will be encrypted without edit content permission
  -noannotations    PDF file will be encrypted without edit annotation permission
  -a                enables accessibility features (Tagged PDF etc., default off)
  -pdfprofile prof  PDF file will be generated with the specified profile
                    (Examples for prof: PDF/A-1b or PDF/X-3:2003)

  -conserve         Enable memory-conservation policy (trades memory-consumption for disk I/O)
                    (Note: currently only influences whether the area tree is serialized.)

 [INPUT]
  infile            xsl:fo input file (the same as the next)
                    (use '-' for infile to pipe input from stdin)
  -fo  infile       xsl:fo input file
  -xml infile       xml input file, must be used together with -xsl
  -atin infile      area tree input file
  -ifin infile      intermediate format input file
  -imagein infile   image input file (piping through stdin not supported)
  -xsl stylesheet   xslt stylesheet

  -param name value <value> to use for parameter <name> in xslt stylesheet
                    (repeat '-param name value' for each parameter)

  -catalog          use catalog resolver for input XML and XSLT files
 [OUTPUT]
  outfile           input will be rendered as PDF into outfile
                    (use '-' for outfile to pipe output to stdout)
  -pdf outfile      input will be rendered as PDF (outfile req'd)
  -pdfa1b outfile   input will be rendered as PDF/A-1b compliant PDF
                    (outfile req'd, same as "-pdf outfile -pdfprofile PDF/A-1b")
  -awt              input will be displayed on screen
  -rtf outfile      input will be rendered as RTF (outfile req'd)
  -pcl outfile      input will be rendered as PCL (outfile req'd)
  -ps outfile       input will be rendered as PostScript (outfile req'd)
  -afp outfile      input will be rendered as AFP (outfile req'd)
  -tiff outfile     input will be rendered as TIFF (outfile req'd)
  -png outfile      input will be rendered as PNG (outfile req'd)
  -txt outfile      input will be rendered as plain text (outfile req'd)
  -at [mime] out    representation of area tree as XML (outfile req'd)
                    specify optional mime output to allow the AT to be converted
                    to final format later
  -if [mime] out    representation of document in intermediate format XML (outfile req'd)
                    specify optional mime output to allow the IF to be converted
                    to final format later
  -print            input file will be rendered and sent to the printer
                    see options with "-print help"
  -out mime outfile input will be rendered using the given MIME type
                    (outfile req'd) Example: "-out application/pdf D:\out.pdf"
                    (Tip: "-out list" prints the list of supported MIME types)
  -svg outfile      input will be rendered as an SVG slides file (outfile req'd)
                    Experimental feature - requires additional fop-sandbox.jar.

  -foout outfile    input will only be XSL transformed. The intermediate
                    XSL-FO file is saved and no rendering is performed.
                    (Only available if you use -xml and -xsl parameters)


 [Examples]
  fop foo.fo foo.pdf
  fop -fo foo.fo -pdf foo.pdf (does the same as the previous line)
  fop -xml foo.xml -xsl foo.xsl -pdf foo.pdf
  fop -xml foo.xml -xsl foo.xsl -foout foo.fo
  fop -xml - -xsl foo.xsl -pdf -
  fop foo.fo -mif foo.mif
  fop foo.fo -rtf foo.rtf
  fop foo.fo -print
  fop foo.fo -awt


D:\tmp\tmp_dev_root\cgwin\home\CLi\develop\docbook\tools\fop>

 

参考这里:HowTo build FOP alternatively,猜测,不是是否可能是由于没有指定正确的java class的环境变量,导致找不到xmlgraphics的库,所以才无法运行的。

去环境变量CLASSPATH中添加了;%FOP_HOME%\lib\xmlgraphics-commons-1.4.jar;

其中:

FOP_HOME = D:\tmp\tmp_dev_root\cgwin\home\CLi\develop\docbook\tools\fop;

然后运行,出现这样的错误:

CLi@PC-CLI-1 ~/develop/docbook/tools/fop
$ ./fop
cygwin warning:
  MS-DOS style path detected: D:\tmp\tmp_dev_root\cgwin\home\CLi\develop\docbook                                                                                                    \tools\fop;
  Preferred POSIX equivalent is: /home/CLi/develop/docbook/tools/fop;
  CYGWIN environment variable option "nodosfilewarning" turns off this warning.
  Consult the user's guide for more details about POSIX paths:
    http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xmlgraphic                                                                                                    s/image/loader/ImageContext
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClassCond(Unknown Source)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at java.security.SecureClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.access$000(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at org.apache.fop.cli.CommandLineOptions.<init>(CommandLineOptions.java:                                                                                                    121)
        at org.apache.fop.cli.Main.startFOP(Main.java:157)
        at org.apache.fop.cli.Main.main(Main.java:205)
Caused by: java.lang.ClassNotFoundException: org.apache.xmlgraphics.image.loader                                                                                                    .ImageContext
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 15 more

所以,再去试试。

结果试了半天,还是不行。所以,放弃。

11.还是先去试试cmd中的fop吧。

结果执行:

D:\tmp\tmp_dev_root\cgwin\home\CLi\develop\docbook\tools\fop>fop -c D:\tmp\tmp_dev_root\cgwin\etc\fop\fop.xconf D:\tmp\tmp_dev_root\cgwin\home\CLi\develop\docbook\written\test\fo\cnBookTest.fo -pdf D:\tmp\tmp_dev_root\cg
win\home\CLi\develop\docbook\written\test\output\pdf\cnBookTest.pdf

最后结果也出错了:

WARNING: xHeight value could not be determined. The font may not work as expected.
Apr 26, 2012 3:31:46 PM org.apache.fop.cli.Main startFOP
SEVERE: Exception
org.apache.fop.apps.FOPException: Failed to resolve font with embed-url 'file:///usr/local/share/fonts/msfonts/simsun.ttc'
        at org.apache.fop.util.LogUtil.handleError(LogUtil.java:38)
        at org.apache.fop.fonts.FontInfoConfigurator.getFontInfo(FontInfoConfigurator.java:212)
        at org.apache.fop.fonts.FontInfoConfigurator.addFonts(FontInfoConfigurator.java:168)
        at org.apache.fop.fonts.FontInfoConfigurator.configure(FontInfoConfigurator.java:100)
        at org.apache.fop.render.PrintRendererConfigurator.buildFontList(PrintRendererConfigurator.java:106)
        at org.apache.fop.render.PrintRendererConfigurator.setupFontInfo(PrintRendererConfigurator.java:129)
        at org.apache.fop.render.intermediate.IFUtil.setupFonts(IFUtil.java:165)
        at org.apache.fop.render.intermediate.IFRenderer.setupFontInfo(IFRenderer.java:181)
        at org.apache.fop.area.RenderPagesModel.<init>(RenderPagesModel.java:73)
        at org.apache.fop.area.AreaTreeHandler.setupModel(AreaTreeHandler.java:130)
        at org.apache.fop.area.AreaTreeHandler.<init>(AreaTreeHandler.java:102)
        at org.apache.fop.render.RendererFactory.createFOEventHandler(RendererFactory.java:359)
        at org.apache.fop.fo.FOTreeBuilder.<init>(FOTreeBuilder.java:105)
        at org.apache.fop.apps.Fop.createDefaultHandler(Fop.java:101)
        at org.apache.fop.apps.Fop.<init>(Fop.java:79)
        at org.apache.fop.apps.FopFactory.newFop(FopFactory.java:271)
        at org.apache.fop.cli.InputHandler.renderTo(InputHandler.java:109)
        at org.apache.fop.cli.Main.startFOP(Main.java:174)
        at org.apache.fop.cli.Main.main(Main.java:205)

所以,要去改一下那个font地址。

改成如下内容:

        <!--
        <font metrics-url="file:///etc/fop/simsun.xml" kerning="yes" embed-url="file:///usr/local/share/fonts/msfonts/simsun.ttc">
        -->
        <font metrics-url="D:\tmp\tmp_dev_root\cgwin\etc\fop\simsun.xml" kerning="yes" embed-url="D:\tmp\tmp_dev_root\cgwin\usr\share\fonts\msfonts\simsun.ttc">
        
          <font-triplet name="SimSun" style="normal" weight="normal"/>
          <font-triplet name="SimSun" style="normal" weight="bold"/>

          <font-triplet name="SimSun" style="italic" weight="normal"/>
          <font-triplet name="SimSun" style="italic" weight="bold"/>
        </font>

        <!--
        <font metrics-url="file:///etc/fop/simhei.xml" kerning="yes" embed-url="file:///usr/local/share/fonts/msfonts/simhei.ttf">
        -->
        <font metrics-url="D:\tmp\tmp_dev_root\cgwin\etc\fop\simhei.xml" kerning="yes" embed-url="D:\tmp\tmp_dev_root\cgwin\usr\share\fonts\msfonts\simhei.ttf">
          <font-triplet name="SimHei" style="normal" weight="normal"/>
          <font-triplet name="SimHei" style="normal" weight="bold"/>

          <font-triplet name="SimHei" style="italic" weight="normal"/>
          <font-triplet name="SimHei" style="italic" weight="bold"/>
        </font>

        <directory recursive="true">/usr/share/fonts/</directory>
        <auto-detect/>

然后最后就可以生成pdf了:

D:\tmp\tmp_dev_root\cgwin\home\CLi\develop\docbook\tools\fop>fop -c D:\tmp\tmp_dev_root\cgwin\etc\fop\fop.xconf D:\tmp\tmp_dev_root\cgwin\home\CLi\develop\docbook\written\test\fo\cnBookTest.fo -pdf D:\tmp\tmp_dev_root\cg
win\home\CLi\develop\docbook\written\test\output\pdf\cnBookTest.pdf
Apr 26, 2012 3:35:39 PM org.apache.fop.apps.FopFactoryConfigurator configure
INFO: Default page-height set to: 11in
Apr 26, 2012 3:35:39 PM org.apache.fop.apps.FopFactoryConfigurator configure
INFO: Default page-width set to: 8.26in
Apr 26, 2012 3:35:39 PM org.apache.fop.fonts.truetype.TTFFile guessVerticalMetricsFromGlyphBBox
WARNING: xHeight value could not be determined. The font may not work as expected.
Apr 26, 2012 3:35:40 PM org.apache.fop.fonts.truetype.TTFFile checkTTC
INFO: This is a TrueType collection file with 4 fonts
。。。。。。。。。。
Apr 26, 2012 3:35:46 PM org.apache.fop.events.LoggingEventListener processEvent
WARNING: Font "Symbol,normal,700" not found. Substituting with "Symbol,normal,400".
Apr 26, 2012 3:35:46 PM org.apache.fop.events.LoggingEventListener processEvent
WARNING: Font "ZapfDingbats,normal,700" not found. Substituting with "ZapfDingbats,normal,400".
Apr 26, 2012 3:35:46 PM org.apache.fop.hyphenation.Hyphenator getHyphenationTree
SEVERE: Couldn't find hyphenation pattern zh_cn
Apr 26, 2012 3:35:46 PM org.apache.fop.fonts.truetype.TTFFile checkTTC
INFO: This is a TrueType collection file with 2 fonts
Apr 26, 2012 3:35:46 PM org.apache.fop.fonts.truetype.TTFFile checkTTC
INFO: Containing the following fonts:
Apr 26, 2012 3:35:46 PM org.apache.fop.fonts.truetype.TTFFile checkTTC
INFO: SimSun <-- selected
Apr 26, 2012 3:35:46 PM org.apache.fop.fonts.truetype.TTFFile checkTTC
INFO: NSimSun

生成的中文pdf效果如下:

cn docbook pdf

总之,虽然很折腾,而且也没发成功的在cygwin下面运行java,fop等工具,但是最后还是可以在windows下用的。

余下的工作,就是如何继续折腾,添加其他字体支持,生成更复杂的pdf文档了。

12.刚才又折腾了一下,目前的可以运行的方式是:

(1)在cygwin中:

CLi@PC-CLI-1 ~/develop/docbook/written/test
$ xsltproc.exe -o fo/cnBookTest.fo /home/CLi/develop/docbook/tools/docbook-xsl-ns-1.76.1/fo/docbook_fo.xsl cnBookTest.xml
Making portrait pages on USletter paper (8.5inx11in)

生成对应的fo文件。

(2)然后再去windows的cmd中:

D:\tmp\tmp_dev_root\cgwin\home\CLi\develop\docbook\written\test>fop -c D:\tmp\tmp_dev_root\cgwin\etc\fop\fop.xconf D:\tmp\tmp_dev_root\cgwin\home\CLi\develop\docbook\written\test\fo\cnBookTest.fo -pdf D:\tmp\tmp_dev_root
\cgwin\home\CLi\develop\docbook\written\test\output\pdf\cnBookTest.pdf
Apr 26, 2012 4:23:58 PM org.apache.fop.apps.FopFactoryConfigurator configure
INFO: Default page-height set to: 11in
Apr 26, 2012 4:23:58 PM org.apache.fop.apps.FopFactoryConfigurator configure
INFO: Default page-width set to: 8.26in
Apr 26, 2012 4:24:00 PM org.apache.fop.events.LoggingEventListener processEvent
WARNING: Font "Symbol,normal,700" not found. Substituting with "Symbol,normal,400".
Apr 26, 2012 4:24:00 PM org.apache.fop.events.LoggingEventListener processEvent
WARNING: Font "ZapfDingbats,normal,700" not found. Substituting with "ZapfDingbats,normal,400".
Apr 26, 2012 4:24:00 PM org.apache.fop.hyphenation.Hyphenator getHyphenationTree
SEVERE: Couldn't find hyphenation pattern zh_cn
Apr 26, 2012 4:24:00 PM org.apache.fop.fonts.truetype.TTFFile checkTTC
INFO: This is a TrueType collection file with 2 fonts
Apr 26, 2012 4:24:00 PM org.apache.fop.fonts.truetype.TTFFile checkTTC
INFO: Containing the following fonts:
Apr 26, 2012 4:24:00 PM org.apache.fop.fonts.truetype.TTFFile checkTTC
INFO: SimSun <-- selected
Apr 26, 2012 4:24:00 PM org.apache.fop.fonts.truetype.TTFFile checkTTC
INFO: NSimSun

生成对应的pdf文件的。

转载请注明:在路上 » 【记录】docbook 5.0的折腾过程

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
83 queries in 0.197 seconds, using 22.28MB memory