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

【已解决】Docbook的pdf,去除正文对于标题的缩进indent + 【顺带实现】给docbook的pdf添加bookmark书签的功能

Docbook crifan 2559浏览 0评论

【问题】

docbook生成的pdf中,正文的内容,相对于标题,有一个缩进:

原先的输出,正文内容和标题是有缩进的

很是不好看,也浪费空间。

想要去除这个缩进。

【解决过程】

1.对于pdf中的输入的格式控制,经过之前的折腾,知道了,要么是参数配置,要么是写xsl方面的代码去控制。

而对于参数控制方面,觉得是最高效的,所以想先去找找是否这方面的参数的配置。

由于之前就知道:

DocBook XSL Stylesheets: Reference Documentation

中的:

2. FO Parameter Reference

所以,去其中找了找,最后还真发现了和正文(body)以及缩进(indent)相关的设置:

body.start.indent — The start-indent for the body text

2.参考其介绍,去试了试添加:

–stringparam fop.extensions 1

结果出错:

CLi@PC-CLI-1 ~/develop/docbook/books/VBR/VBR/src
$ xsltproc.exe --stringparam section.autolabel 1 --stringparam section.label.includes.component.label 1 --stringparam bibliography.numbered 1 --stringparam ulink.show 1 --stringparam ulink.footnotes 1 --stringparam table.cell.border.color green --stringparam table.frame.border.thickness 2pt --stringparam fop.extensions 1 --xinclude -o ../output/fo/MPEG_VBR.fo /home/CLi/develop/docbook/config/docbook-xsl-ns-1.76.1/fo/docbook_crl.xsl MPEG_VBR.xml
Making portrait pages on USletter paper (8.5inx11in)

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 D:/tmp/tmp_dev_root/cgwin/home/CLi/develop/docbook/books/VBR/VBR/output/fo/MPEG_VBR.fo -pdf D:/tmp/tmp_dev_root/cgwin/home/CLi/develop/docbook/books/VBR/VBR/output/pdf/MPEG_VBR.pdf
May 7, 2012 11:06:57 AM org.apache.fop.apps.FopFactoryConfigurator configure
INFO: Default page-height set to: 11in
May 7, 2012 11:06:57 AM org.apache.fop.apps.FopFactoryConfigurator configure
INFO: Default page-width set to: 8.26in
May 7, 2012 11:06:58 AM org.apache.fop.events.LoggingEventListener processEvent
WARNING: Unknown formatting object "{http://xml.apache.org/fop/extensions}outline" encountered (a child of fo:root}. (See position 2:12496)
May 7, 2012 11:06:58 AM org.apache.fop.events.LoggingEventListener processEvent
WARNING: Unknown formatting object "{http://xml.apache.org/fop/extensions}label" encountered (a child of outline}. (See position 2:12507)
May 7, 2012 11:06:58 AM org.apache.fop.events.LoggingEventListener processEvent
WARNING: Unknown formatting object "{http://xml.apache.org/fop/extensions}outline" encountered (a child of fo:root}. (See position 2:12664)
May 7, 2012 11:06:58 AM org.apache.fop.events.LoggingEventListener processEvent
WARNING: Unknown formatting object "{http://xml.apache.org/fop/extensions}label" encountered (a child of outline}. (See position 2:12675)
May 7, 2012 11:06:58 AM org.apache.fop.events.LoggingEventListener processEvent
WARNING: Unknown formatting object "{http://xml.apache.org/fop/extensions}outline" encountered (a child of fo:root}. (See position 2:12796)
May 7, 2012 11:06:58 AM org.apache.fop.events.LoggingEventListener processEvent
WARNING: Unknown formatting object "{http://xml.apache.org/fop/extensions}label" encountered (a child of outline}. (See position 2:12807)
May 7, 2012 11:06:58 AM org.apache.fop.events.LoggingEventListener processEvent
WARNING: Unknown formatting object "{http://xml.apache.org/fop/extensions}outline" encountered (a child of outline}. (See position 2:12870)
May 7, 2012 11:06:58 AM org.apache.fop.events.LoggingEventListener processEvent
WARNING: Unknown formatting object "{http://xml.apache.org/fop/extensions}label" encountered (a child of outline}. (See position 2:12881)
May 7, 2012 11:06:58 AM org.apache.fop.cli.Main startFOP
SEVERE: Exception
javax.xml.transform.TransformerException: org.apache.fop.apps.FOPException: file:/D:/tmp/tmp_dev_root/cgwin/home/CLi/develop/docbook/books/VBR/VBR/output/fo/MPEG_VBR.fo:2:12964: Error(2/12964): No element mapping definition found for (Namespace URI: "http://xml.apache.org/fop/extensions", Local Name: "destination")
        at org.apache.fop.cli.InputHandler.transformTo(InputHandler.java:302)
        at org.apache.fop.cli.InputHandler.renderTo(InputHandler.java:130)
        at org.apache.fop.cli.Main.startFOP(Main.java:174)
        at org.apache.fop.cli.Main.main(Main.java:205)
Caused by: javax.xml.transform.TransformerException: org.apache.fop.apps.FOPException: file:/D:/tmp/tmp_dev_root/cgwin/home/CLi/develop/docbook/books/VBR/VBR/output/fo/MPEG_VBR.fo:2:12964: Error(2/12964): No element mapping definition found for (Namespace URI: "http://xml.apache.org/fop/extensions", Local Name: "destination")
        at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:501)
        at org.apache.fop.cli.InputHandler.transformTo(InputHandler.java:299)
        ... 3 more
Caused by: org.apache.fop.apps.FOPException: file:/D:/tmp/tmp_dev_root/cgwin/home/CLi/develop/docbook/books/VBR/VBR/output/fo/MPEG_VBR.fo:2:12964: Error(2/12964): No element mapping definition found for (Namespace URI: "http://xml.apache.org/fop/extensions", Local Name: "destination")
        at org.apache.fop.fo.ElementMappingRegistry.findFOMaker(ElementMappingRegistry.java:144)
        at org.apache.fop.fo.FOTreeBuilder$MainFOHandler.findFOMaker(FOTreeBuilder.java:396)
        at org.apache.fop.fo.FOTreeBuilder$MainFOHandler.startElement(FOTreeBuilder.java:271)
        at org.apache.fop.fo.FOTreeBuilder.startElement(FOTreeBuilder.java:171)
        at org.apache.xalan.transformer.TransformerIdentityImpl.startElement(TransformerIdentityImpl.java:1072)
        at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
        at org.apache.xerces.parsers.AbstractXMLDocumentParser.emptyElement(Unknown Source)
        at org.apache.xerces.xinclude.XIncludeHandler.emptyElement(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)
        ... 4 more

---------

javax.xml.transform.TransformerException: org.apache.fop.apps.FOPException: file:/D:/tmp/tmp_dev_root/cgwin/home/CLi/develop/docbook/books/VBR/VBR/output/fo/MPEG_VBR.fo:2:12964: Error(2/12964): No element mapping definition found for (Namespace URI: "http://xml.apache.org/fop/extensions", Local Name: "destination")
        at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:501)
        at org.apache.fop.cli.InputHandler.transformTo(InputHandler.java:299)
        at org.apache.fop.cli.InputHandler.renderTo(InputHandler.java:130)
        at org.apache.fop.cli.Main.startFOP(Main.java:174)
        at org.apache.fop.cli.Main.main(Main.java:205)
Caused by: org.apache.fop.apps.FOPException: file:/D:/tmp/tmp_dev_root/cgwin/home/CLi/develop/docbook/books/VBR/VBR/output/fo/MPEG_VBR.fo:2:12964: Error(2/12964): No element mapping definition found for (Namespace URI: "http://xml.apache.org/fop/extensions", Local Name: "destination")
        at org.apache.fop.fo.ElementMappingRegistry.findFOMaker(ElementMappingRegistry.java:144)
        at org.apache.fop.fo.FOTreeBuilder$MainFOHandler.findFOMaker(FOTreeBuilder.java:396)
        at org.apache.fop.fo.FOTreeBuilder$MainFOHandler.startElement(FOTreeBuilder.java:271)
        at org.apache.fop.fo.FOTreeBuilder.startElement(FOTreeBuilder.java:171)
        at org.apache.xalan.transformer.TransformerIdentityImpl.startElement(TransformerIdentityImpl.java:1072)
        at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
        at org.apache.xerces.parsers.AbstractXMLDocumentParser.emptyElement(Unknown Source)
        at org.apache.xerces.xinclude.XIncludeHandler.emptyElement(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)
        ... 4 more
---------
org.apache.fop.apps.FOPException: file:/D:/tmp/tmp_dev_root/cgwin/home/CLi/develop/docbook/books/VBR/VBR/output/fo/MPEG_VBR.fo:2:12964: Error(2/12964): No element mapping definition found for (Namespace URI: "http://xml.apache.org/fop/extensions", Local Name: "destination")
        at org.apache.fop.fo.ElementMappingRegistry.findFOMaker(ElementMappingRegistry.java:144)
        at org.apache.fop.fo.FOTreeBuilder$MainFOHandler.findFOMaker(FOTreeBuilder.java:396)
        at org.apache.fop.fo.FOTreeBuilder$MainFOHandler.startElement(FOTreeBuilder.java:271)
        at org.apache.fop.fo.FOTreeBuilder.startElement(FOTreeBuilder.java:171)
        at org.apache.xalan.transformer.TransformerIdentityImpl.startElement(TransformerIdentityImpl.java:1072)
        at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
        at org.apache.xerces.parsers.AbstractXMLDocumentParser.emptyElement(Unknown Source)
        at org.apache.xerces.xinclude.XIncludeHandler.emptyElement(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:299)
        at org.apache.fop.cli.InputHandler.renderTo(InputHandler.java:130)
        at org.apache.fop.cli.Main.startFOP(Main.java:174)
        at org.apache.fop.cli.Main.main(Main.java:205)

然后参考fop1.extensions,去试了试:

–stringparam fop1.extensions 1

倒是可以的成功生成pdf的,虽然没有达到我要的去除indent,但是却实现了我要的,添加bookmark的效果:

没去除indent,但是却有了bookmark

3.后来,在看:Pagination and General Styles – body.start.indent,的时候,突然看到,其实是可以手动给body.start.indent赋值的,所以就去添加了:

–stringparam body.start.indent 0pt

然后就可以了:

CLi@PC-CLI-1 ~/develop/docbook/books/VBR/VBR/src
$ xsltproc.exe --stringparam section.autolabel 1 --stringparam section.label.includes.component.label 1 --stringparam bibliography.numbered 1 --stringparam ulink.show 1 --stringparam ulink.footnotes 1 --stringparam table.cell.border.color green --stringparam table.frame.border.thickness 2pt --stringparam fop1.extensions 1 --stringparam body.start.indent 0pt --xinclude -o ../output/fo/MPEG_VBR.fo /home/CLi/develop/docbook/config/docbook-xsl-ns-1.76.1/fo/docbook_crl.xsl MPEG_VBR.xml
Making portrait pages on USletter paper (8.5inx11in)

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 D:/tmp/tmp_dev_root/cgwin/home/CLi/develop/docbook/books/VBR/VBR/output/fo/MPEG_VBR.fo -pdf D:/tmp/tmp_dev_root/cgwin/home/CLi/develop/docbook/books/VBR/VBR/output/pdf/MPEG_VBR.pdf                         May 7, 2012 11:20:28 AM org.apache.fop.apps.FopFactoryConfigurator configure
INFO: Default page-height set to: 11in
May 7, 2012 11:20:28 AM org.apache.fop.apps.FopFactoryConfigurator configure
INFO: Default page-width set to: 8.26in
May 7, 2012 11:20:29 AM org.apache.fop.events.LoggingEventListener processEvent
WARNING: Font "Symbol,normal,700" not found. Substituting with "Symbol,normal,400".
May 7, 2012 11:20:29 AM org.apache.fop.events.LoggingEventListener processEvent
WARNING: Font "ZapfDingbats,normal,700" not found. Substituting with "ZapfDingbats,normal,400".
May 7, 2012 11:20:29 AM org.apache.fop.hyphenation.Hyphenator getHyphenationTree
SEVERE: Couldn't find hyphenation pattern zh_cn
May 7, 2012 11:20:35 AM org.apache.fop.events.LoggingEventListener processEvent
WARNING: Line 2 of a paragraph overflows the available area by 12112 millipoints. (See position 102:732)

生成pdf效果如下:

取消了缩进,也带bookmark

【总结】

想要取消正文的缩进,给xsltproc添加参数即可:

--stringparam body.start.indent 0pt 

 

【另外】

顺带知道了,想要给pdf添加标签bookmark,添加这个参数即可:

--stringparam fop1.extensions 1 

转载请注明:在路上 » 【已解决】Docbook的pdf,去除正文对于标题的缩进indent + 【顺带实现】给docbook的pdf添加bookmark书签的功能

发表我的评论
取消评论

表情

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

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
82 queries in 0.209 seconds, using 22.37MB memory