最新消息:20190717 VPS服务器:Vultr新加坡,WordPress主题:大前端D8,统一介绍入口:关于

【已放弃解决】将docbook的xml,用xsltproc和fop生成rtf时出错:WARNING: Only simple-page-masters are supported on page-sequences. Using default simple-page-master from page-sequence-master "titlepage" "front" "body" "back",WARNING: RTF: fo:leader reference-area not supported + 【记录】折腾openjade和XFC去生成RTF

Docbook crifan 923浏览 0评论

【问题】

已经可以成功用fop将之前xsltproc所将docbook生成的fo文件,生成对应的rtf了:

【记录】将docbook的xml源码,通过xsltproc和FOP生成(可用word打开的)RTF(Word兼容)格式

但是中间过程出错:

CLi@PC-CLI-1 ~/develop/docbook/books/VBR/VBR/src
$ D:/tmp/tmp_dev_root/cgwin/home/CLi/develop/docbook/tools/fop/fop.cmd -c D:/tmp/tmp_dev_root/cgwin/home/CLi/develop/docbook/config/fop/conf/fop.xconf ../output/fo/MPEG_VBR.fo -rtf ../output/rtf/MPEG_VBR.rtf
May 10, 2012 3:02:58 PM org.apache.fop.apps.FopFactoryConfigurator configure
INFO: Default page-height set to: 11in
May 10, 2012 3:02:58 PM org.apache.fop.apps.FopFactoryConfigurator configure
INFO: Default page-width set to: 8.26in
May 10, 2012 3:02:59 PM org.apache.fop.events.LoggingEventListener processEvent
WARNING: Only simple-page-masters are supported on page-sequences. Using default simple-page-master from page-sequence-master "titlepage". (See position 2:28286)
May 10, 2012 3:02:59 PM org.apache.fop.events.LoggingEventListener processEvent
WARNING: Only simple-page-masters are supported on page-sequences. Using default simple-page-master from page-sequence-master "lot". (See position 10:2150)
May 10, 2012 3:02:59 PM org.apache.fop.render.rtf.TextAttributesConverter convertLeaderAttributes
WARNING: RTF: fo:leader reference-area not supported

May 10, 2012 3:02:59 PM org.apache.fop.events.LoggingEventListener processEvent
WARNING: Only simple-page-masters are supported on page-sequences. Using default simple-page-master from page-sequence-master "front". (See position 10:79508)
May 10, 2012 3:02:59 PM org.apache.fop.events.LoggingEventListener processEvent
WARNING: Only simple-page-masters are supported on page-sequences. Using default simple-page-master from page-sequence-master "body". (See position 10:91114)

May 10, 2012 3:03:01 PM org.apache.fop.datatypes.LengthBase getBaseLength
SEVERE: getBaseLength called without context

May 10, 2012 3:03:02 PM org.apache.fop.events.LoggingEventListener processEvent
WARNING: Only simple-page-masters are supported on page-sequences. Using default simple-page-master from page-sequence-master "back". (See position 97:285)

想要解决这一堆的warning。

【解决过程】

1.找了下,看到官网RTF的解释中,已经提到了,上述问题中的:

Only a single page-master is supported

Not all variations of fo:leader are supported (RTF limitation)

所以,基本上,上述的warning,都是可以在”可预料”的范围内的。

同时,生成的rtf显示的效果,也有很多小问题,其也提到了此点的,并且说如果希望输出的rtf效果更好,那么建议用其他的工具,比如“Using other editable formats like Open Document Format”。

所以,由于又看到了Cygwin已经有了openjade了:

CLi@PC-CLI-1 ~/develop/docbook/books/VBR/VBR/src
$ openjade.exe -h
Usage: openjade [OPTION] SYSID...
Short options need the same arguments as their long forms.
Options with a "doc-"/"spec-" prefix apply only to the document/specification.
  -b, --encoding=NAME         Use encoding NAME for output.
  -f, --error-file=FILE       Append error messages to file FILE.
  -v, --version               Display the program version.
  -h, --help                  Show this help text.
  -c, --catalog=SYSID         Use catalog SYSID.
  -C, --catalogs              Arguments are catalogs, use DOCUMENT entry.
  -D, --directory=DIRECTORY   Search files in directory DIRECTORY.
  -R, --restricted            Restrict file reading (for use in Web apps).
  -a, --activate=NAME         Make doctype or linktype NAME active.
  -A, --architecture=NAME     Parse wrt. architecture NAME.
  -E, --max-errors=NUMBER     Give up after NUMBER errors.
  -e, --open-entities         Show open entities in error messages.
  -g, --open-elements         Show open elements in error messages.
  -n, --error-numbers         Show error numbers in error messages.
  -x, --references            Show references in error messages.
  -i, --include=NAME          Define parameter entity NAME as "INCLUDE".
  -w, --warning=TYPE          Enable warning TYPE.
  -2                          Enable experimental DSSSL extensions.
  -G, --debug                 Debug mode.
  -d, --specification=SYSID   Use DSSSL specification SYSID.
  -V, --define=DEFINITION     Pretend that DEFINITION appeared in the specification.
  -s, --strict                Strict DSSSL compliance mode.
  -T, --spec-title=NAME       Use DSSSL specification with title NAME.
  --doc-open-entities         Show open entities in error messages.
  --doc-open-elements         Show open elements in error messages.
  --doc-error-numbers         Show error numbers in error messages.
  --doc-references            Show references in error messages.
  --doc-include=NAME          Define parameter entity NAME as "INCLUDE".
  --doc-warning=TYPE          Enable warning TYPE.
  --spec-open-entities        Show open entities in error messages.
  --spec-open-elements        Show open elements in error messages.
  --spec-error-numbers        Show error numbers in error messages.
  --spec-references           Show references in error messages.
  --spec-include=NAME         Define parameter entity NAME as "INCLUDE".
  --spec-warning=TYPE         Enable warning TYPE.
  -t, --output-type=TYPE      Use the backend TYPE.
  -o, --output-file=FILE      Send output to FILE.

所以可以去试试openjade了。

2.想要去用openjade,但是不值得网上很多人说的那个docbook.dsl是在哪里的。

后来参考:4.4.2. XML 轉換到 RTF,找到了对应的我此处的位置:

CLi@PC-CLI-1 ~/develop/docbook/books/VBR/VBR/src
$ ls /usr/share/sgml/docbook/dsssl-stylesheets/print/ -l
total 613
-rw-r--r-- 1 CLi Domänen-Benutzer   5052 Jan 29  2010 dbadmon.dsl
。。。
-rw-r--r-- 1 CLi Domänen-Benutzer   8674 Jan 29  2010 docbook.dsl
-rw-r--r-- 1 CLi Domänen-Benutzer    913 Jan 29  2010 notoc.dsl
-rw-r--r-- 1 CLi Domänen-Benutzer   1174 Jan 29  2010 plain.dsl
-rw-r--r-- 1 CLi Domänen-Benutzer    438 Jan 29  2010 version.dsl

然后就可以去试试了。

后来参考了:

Using openjade to convert from XML DocBook to RTF

DocBook XML/SGML Processing Using OpenJade – 4.2.3. XML to RTF

去试了半天,试了如下的一堆命令:

openjade -t rtf -d /usr/local/share/sgml/docbook/dsssl/print/docbook.dsl /usr/local/share/sgml/docbook/dtds/decls/xml.dcl test.xml

openjade -t rtf -E 0 -d /usr/share/sgml/docbook/dsssl-stylesheets/print/docbook.dsl /usr/share/sgml/docbook/sgml-dtd-4.5/docbook.dcl MPEG_VBR.xml -o ../output/rtf/openjade/MPEG_VBR.rtf

openjade -t rtf /usr/share/sgml/docbook/sgml-dtd-4.5/docbook.dcl -o ../output/rtf/openjade/MPEG_VBR.rtf MPEG_VBR.xml

openjade -t rtf -E 0 -d /usr/share/sgml/docbook/dsssl-stylesheets/print/docbook.dsl /usr/share/sgml/docbook/sgml-dtd-4.5/docbook.dcl MPEG_VBR.xml

结果不是始终无任何输出,就是

Segmentation fault (core dumped)

所以,还是打算放弃了,毕竟再去将xsltproc+fop换到openjade,又是一堆麻烦事情,不值得单独为了rtf,而再花这么多精力。除非等,等以后有空再去弄。

3.那就继续回来折腾fop输出rtf的问题。看看是否可以找到解决方法。

(1)从这里:

Re: RTF, nested tables, context enhancement – status

找到rtf的spec:

Word 2003: Rich Text Format (RTF) Specification, version 1.8

下载后解压可得到:Word2003RTFSpec.doc

其中详细解释了rtf的规范,但是太多了,也看不懂。

而且从上述帖子得知,我本来所要打算去试试XMLMIND的,结果也不用去试了,因为其也提到,其输出rtf是好,但是是需要付费的。而免费版的,之前看到介绍了,是要每一页都有提示,所以还是很不爽的。

也许,也是可以去试试XMLMind的。暂时不去试了。

(2)这里:Re: RTF-Output with FOP 0.93 looks terrible,也遇到了类似问题:

The Table of Content are missing the pagenumbers for each listed chapter

但是也是无解。

(3)参考:Re: [XSL-FO][docbook]Problem print line in table of contents,但也没效果。

(4)有人倒是建议,如果可以,你自己去实现对应的函数:

Re: RTF generation and total page count

但是很明显,偶还没到那一步,所以无解。

4.后来去Apache FOP: Nightly Snapshots下载了最新的FOP:fop-20120509-bin.tar.gz ,想要试试其生成出来的rtf是否会更好点,结果出错了:

CLi@PC-CLI-1 ~/develop/docbook/books/VBR/VBR/src
$ D:/tmp/tmp_dev_root/cgwin/home/CLi/develop/docbook/tools/fop_latest/fop-20120509/fop.bat -c D:/tmp/tmp_dev_root/cgwin/home/CLi/develop/docbook/config/fop/conf/fop.xconf ../output/fo/MPEG_VBR.fo -rtf ../output/rtf/fop/MPEG_VBR_newFop.rtf
May 10, 2012 5:04:06 PM org.apache.fop.apps.FopFactoryConfigurator configure
INFO: Default page-height set to: 11in
May 10, 2012 5:04:06 PM org.apache.fop.apps.FopFactoryConfigurator configure
INFO: Default page-width set to: 8.26in
May 10, 2012 5:04:07 PM org.apache.fop.events.LoggingEventListener processEvent
WARNING: Only simple-page-masters are supported on page-sequences. Using default simple-page-master from page-sequence-master "titlepage". (See position 2:28286)
May 10, 2012 5:04:07 PM org.apache.fop.cli.Main startFOP
SEVERE: Exception
java.lang.NullPointerException
        at org.apache.fop.cli.InputHandler.transformTo(InputHandler.java:303)
        at org.apache.fop.cli.InputHandler.renderTo(InputHandler.java:130)
        at org.apache.fop.cli.Main.startFOP(Main.java:177)
        at org.apache.fop.cli.Main.main(Main.java:208)
Caused by: java.lang.NullPointerException
        at org.apache.fop.render.rtf.RTFHandler.startPageSequence(RTFHandler.java:221)
        at org.apache.fop.fo.pagination.PageSequence.startOfNode(PageSequence.java:119)
        at org.apache.fop.fo.FOTreeBuilder$MainFOHandler.startElement(FOTreeBuilder.java:325)
        at org.apache.fop.fo.FOTreeBuilder.startElement(FOTreeBuilder.java:175)
        at org.apache.xalan.transformer.TransformerIdentityImpl.startElement(TransformerIdentityImpl.java:1072)
        at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
        at org.apache.xerces.xinclude.XIncludeHandler.startElement(Unknown Source)
        at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
        at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
        at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
        at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
        at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
        at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
        at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
        at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
        at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:484)
        at org.apache.fop.cli.InputHandler.transformTo(InputHandler.java:300)
        ... 3 more

---------

java.lang.NullPointerException
        at org.apache.fop.render.rtf.RTFHandler.startPageSequence(RTFHandler.java:221)
        at org.apache.fop.fo.pagination.PageSequence.startOfNode(PageSequence.java:119)
        at org.apache.fop.fo.FOTreeBuilder$MainFOHandler.startElement(FOTreeBuilder.java:325)
        at org.apache.fop.fo.FOTreeBuilder.startElement(FOTreeBuilder.java:175)
        at org.apache.xalan.transformer.TransformerIdentityImpl.startElement(TransformerIdentityImpl.java:1072)
        at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
        at org.apache.xerces.xinclude.XIncludeHandler.startElement(Unknown Source)
        at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
        at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
        at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
        at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
        at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
        at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
        at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
        at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
        at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:484)
        at org.apache.fop.cli.InputHandler.transformTo(InputHandler.java:300)
        at org.apache.fop.cli.InputHandler.renderTo(InputHandler.java:130)
        at org.apache.fop.cli.Main.startFOP(Main.java:177)
        at org.apache.fop.cli.Main.main(Main.java:208)

看来还是不行。

5.后来去fop官网:http://archive.apache.org/dist/xmlgraphics/fop/

没有找到最新版本的bin格式的fop下载。倒是可以下载到其他版本的,包括最新的1.0的版本的。

6.后来去找了那个XMLmind,即XMLmind FO Converter,简称XFC:

XFC version 0.9

然后又去其官网:XMLmind XSL-FO Converter engine去下载了对应的xfc:

http://www.xmlmind.net/foconverter/_download/xfc_perso_java-4_6_1.zip

然后去cygwin中使用,结果转换过程,也是一堆warning:

CLi@PC-CLI-1 ~/develop/docbook/books/VBR/VBR/src
$ /home/CLi/develop/docbook/tools/xfc/xfc_perso_java-4_6_1/bin/fo2rtf.bat ../output/fo/MPEG_VBR.fo ../output/rtf/xfc/MPEG_VBR.rtf
warning: unknown element "bookmark-tree" (file:///D:/tmp/tmp_dev_root/cgwin/home/CLi/develop/docbook/books/VBR/VBR/output/fo/MPEG_VBR.fo, line #2, column #12883)
...
warning: cannot resolve URI "D:/tmp/tmp_dev_root/cgwin/home/CLi/develop/docbook/tools/docbook-xsl-ns-1.76.1/images/colorsvg/tip.svg" (file:///D:/tmp/tmp_dev_root/cgwin/home/CLi/develop/docbook/books/VBR/VBR/output/fo/MPEG_VBR.fo, line #19, column #8169)
warning: bad property value background-color="antiquewhite" (file:///D:/tmp/tmp_dev_root/cgwin/home/CLi/develop/docbook/books/VBR/VBR/output/fo/MPEG_VBR.fo, line #19, column #10464)
....
warning: URI resolver error: unknown protocol: d (file:///D:/tmp/tmp_dev_root/cgwin/home/CLi/develop/docbook/books/VBR/VBR/output/fo/MPEG_VBR.fo, line #19, column #41087)
warning: cannot resolve URI "D:/tmp/tmp_dev_root/cgwin/home/CLi/develop/docbook/tools/docbook-xsl-ns-1.76.1/images/colorsvg/tip.svg" (file:///D:/tmp/tmp_dev_root/cgwin/home/CLi/develop/docbook/books/VBR/VBR/output/fo/MPEG_VBR.fo, line #19, column #41087)
warning: bad property value background-color="antiquewhite" (file:///D:/tmp/tmp_dev_root/cgwin/home/CLi/develop/docbook/books/VBR/VBR/output/fo/MPEG_VBR.fo, line #19, column #43507)
...
warning: URI resolver error: unknown protocol: d (file:///D:/tmp/tmp_dev_root/cgwin/home/CLi/develop/docbook/books/VBR/VBR/output/fo/MPEG_VBR.fo, line #19, column #49432)
warning: cannot resolve URI "D:/tmp/tmp_dev_root/cgwin/home/CLi/develop/docbook/tools/docbook-xsl-ns-1.76.1/images/colorsvg/tip.svg" (file:///D:/tmp/tmp_dev_root/cgwin/home/CLi/develop/docbook/books/VBR/VBR/output/fo/MPEG_VBR.fo, line #19, column #49432)
warning: failed to load image "file:/D:/tmp/tmp_dev_root/cgwin/home/CLi/develop/docbook/books/VBR/VBR/output/fo/images/mpeg_header.png": D:\tmp\tmp_dev_root\cgwin\home\CLi\develop\docbook\books\VBR\VBR\output\fo\images\mpeg_header.png (The system cannot find the path specified) (file:///D:/tmp/tmp_dev_root/cgwin/home/CLi/develop/docbook/books/VBR/VBR/output/fo/MPEG_VBR.fo, line #19, column #51879)
warning: bad property value background-color="antiquewhite" (file:///D:/tmp/tmp_dev_root/cgwin/home/CLi/develop/docbook/books/VBR/VBR/output/fo/MPEG_VBR.fo, line #19, column #55073)
...
warning: URI resolver error: unknown protocol: d (file:///D:/tmp/tmp_dev_root/cgwin/home/CLi/develop/docbook/books/VBR/VBR/output/fo/MPEG_VBR.fo, line #19, column #60203)
warning: cannot resolve URI "D:/tmp/tmp_dev_root/cgwin/home/CLi/develop/docbook/tools/docbook-xsl-ns-1.76.1/images/colorsvg/tip.svg" (file:///D:/tmp/tmp_dev_root/cgwin/home/CLi/develop/docbook/books/VBR/VBR/output/fo/MPEG_VBR.fo, line #19, column #60203)
warning: failed to load image "file:/D:/tmp/tmp_dev_root/cgwin/home/CLi/develop/docbook/books/VBR/VBR/output/fo/images/example.jpg": D:\tmp\tmp_dev_root\cgwin\home\CLi\develop\docbook\books\VBR\VBR\output\fo\images\example.jpg (The system cannot find the path specified) (file:///D:/tmp/tmp_dev_root/cgwin/home/CLi/develop/docbook/books/VBR/VBR/output/fo/MPEG_VBR.fo, line #33, column #131)
warning: bad property value background-color="antiquewhite" (file:///D:/tmp/tmp_dev_root/cgwin/home/CLi/develop/docbook/books/VBR/VBR/output/fo/MPEG_VBR.fo, line #58, column #6457)
...
warning: URI resolver error: unknown protocol: d (file:///D:/tmp/tmp_dev_root/cgwin/home/CLi/develop/docbook/books/VBR/VBR/output/fo/MPEG_VBR.fo, line #78, column #6266)
warning: cannot resolve URI "D:/tmp/tmp_dev_root/cgwin/home/CLi/develop/docbook/tools/docbook-xsl-ns-1.76.1/images/colorsvg/tip.svg" (file:///D:/tmp/tmp_dev_root/cgwin/home/CLi/develop/docbook/books/VBR/VBR/output/fo/MPEG_VBR.fo, line #78, column #6266)
warning: URI resolver error: unknown protocol: d (file:///D:/tmp/tmp_dev_root/cgwin/home/CLi/develop/docbook/books/VBR/VBR/output/fo/MPEG_VBR.fo, line #95, column #858)
warning: cannot resolve URI "D:/tmp/tmp_dev_root/cgwin/home/CLi/develop/docbook/tools/docbook-xsl-ns-1.76.1/images/colorsvg/tip.svg" (file:///D:/tmp/tmp_dev_root/cgwin/home/CLi/develop/docbook/books/VBR/VBR/output/fo/MPEG_VBR.fo, line #95, column #858)

而且生产的rtf,看起来的效果,也并不是很好。

图片没有加载,倒不是其问题,应该是上面的路径没有设置好。

但是其他很多毛病:

1.TOC目录部分,格式很乱:

toc目录很乱 页号也全是0

2表格头部的背景色,不支持antiquewhite:表格头部背景色不支持antiquewhite

3.不支持svg的图片,比如tip.svg:

不支持svg图片

4.公式equation中的内容,都全部丢失了:公式中的内容,都没有了

再加上本身自带的footer的提示:本身自带的footer提示

综合来说,要比fop 1.0所生成的rtf,效果差太多了,所以看来fop 1.0所生成的rtf虽然是有小缺点,但是比起xfc,那还是强很多倍的,至少内容没有丢失的,而且格式上,还是很不错的。

转载请注明:在路上 » 【已放弃解决】将docbook的xml,用xsltproc和fop生成rtf时出错:WARNING: Only simple-page-masters are supported on page-sequences. Using default simple-page-master from page-sequence-master "titlepage" "front" "body" "back",WARNING: RTF: fo:leader reference-area not supported + 【记录】折腾openjade和XFC去生成RTF

发表我的评论
取消评论

表情

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

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
56 queries in 0.294 seconds, using 19.15MB memory