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

【未解决】给docbook生成的pdf中每页都添加上边框

Docbook crifan 3605浏览 0评论

【问题】

希望将docbook生成的pdf中,每页都添加上对应的边框。

就像这样的:

example of added page frame

【解决过程】

1.这里:

Top and bottom margins

倒是介绍了,页面的结构组成。

2.参考:

Borders

给chapter添加frame:

<chapter
    xmlns="http://docbook.org/ns/docbook"
    xmlns:xi="http://www.w3.org/2001/XInclude"
    xmlns:xl="http://www.w3.org/1999/xlink"

    xml:id="ch01_reduced_instruction_set"
	frame="all">

结果,无效。

3.参考:

Borders and background shading

其提到了。

对于加边框border的事情:

html中,是可以通过css控制的;

fo/pdf中,是要再xsl中添加属性去控制的;

目前已经支持的一些:

  • admonitions
  • blockquotes
  • component
  • equations
  • examples
  • figures
  • formal object titles

很明显,其没有对应的针对于整个pdf的page,即fo的单页的内容,去添加border。

所以就想办法,去到对应的fo中,添加一下试试。

参考其中的,添加border试试,把原先的:

<fo:flow flow-name="xsl-region-body" start-indent="0pt" end-indent="0pt">
	  <fo:block id="ch01_reduced_instruction_set">...</fo:block>
	  <fo:block id="toc...ch01_reduced_instruction_set" space-before.minimum="0.5em" space-before.optimum="1em" space-before.maximum="2em" space-after.minimum="0.5em" space-after.optimum="1em" space-after.maximum="2em">...</fo:block>
	  <fo:block text-align="left" font-size="9pt" font-family="Microsoft YaHei,Cambria Math" font-weight="normal" start-indent="0.0in" end-indent="0.0in"/>...</fo:block>
	  <fo:block id="idp8622056">...</fo:block>
	  <fo:block id="idp8624312">...</fo:block>
</fo:flow>

改为:

<fo:flow flow-name="xsl-region-body" start-indent="0pt" end-indent="0pt" border="0.5pt solid blue">
	  <fo:block id="ch01_reduced_instruction_set">...</fo:block>
	  <fo:block id="toc...ch01_reduced_instruction_set" space-before.minimum="0.5em" space-before.optimum="1em" space-before.maximum="2em" space-after.minimum="0.5em" space-after.optimum="1em" space-after.maximum="2em">...</fo:block>
	  <fo:block text-align="left" font-size="9pt" font-family="Microsoft YaHei,Cambria Math" font-weight="normal" start-indent="0.0in" end-indent="0.0in"/>...</fo:block>
	  <fo:block id="idp8622056">...</fo:block>
	  <fo:block id="idp8624312">...</fo:block>
</fo:flow>

然后去由此fo,生成pdf,看看是否有变化。

结果无任何变化。

4.另外再加个背景色:

    <fo:flow flow-name="xsl-region-body" start-indent="0pt" end-indent="0pt" border="0.5pt solid blue" background-color="#E0E0E0">

看看是否能够生效。

结果还是无效。

5.把上述改动,换到第一个fo:block上面:

<fo:flow flow-name="xsl-region-body" start-indent="0pt" end-indent="0pt">
	  <fo:block id="ch01_reduced_instruction_set"  border="0.5pt solid blue" background-color="#E0E0E0">...</fo:block>
	  <fo:block id="toc...ch01_reduced_instruction_set" space-before.minimum="0.5em" space-before.optimum="1em" space-before.maximum="2em" space-after.minimum="0.5em" space-after.optimum="1em" space-after.maximum="2em">...</fo:block>
	  <fo:block text-align="left" font-size="9pt" font-family="Microsoft YaHei,Cambria Math" font-weight="normal" start-indent="0.0in" end-indent="0.0in"/>...</fo:block>
	  <fo:block id="idp8622056"  border="0.5pt solid blue" background-color="#E0E0E0">...</fo:block>
	  <fo:block id="idp8624312"  border="0.5pt solid blue" background-color="#E0E0E0">...</fo:block>
</fo:flow>

试试。结果还是无效。

6.再把对应的border加到对应的细节部分上:

<fo:block id="ch01_reduced_instruction_set">

之下的

<fo:block font-size="24.8832pt" font-weight="bold" border="0.5pt solid blue" background-color="#E0E0E0">

此部分是对应的第一章的标题部分,看看是否有效果。

结果发现是可以,且刚才,对于正文部分的,没显示出来的边框,这下都显示出来了:

all title and body text added border

7.重新改为针对fo:flow加属性:

    <fo:flow flow-name="xsl-region-body" start-indent="0pt" end-indent="0pt" border="0.5pt solid blue" background-color="#E0E0E0">

试试效果。

结果还是不行。

所以看起来是:

fo中,没有page的概念,只有block的概念。

所以,想要对于page加边框的话,貌似没法实现,

只能实现,不完全相同,但是类似的:

针对所有的内容的部分,对应的fo:block,分别加上对应的边框:

<fo:flow flow-name="xsl-region-body" start-indent="0pt" end-indent="0pt">
	  <fo:block id="ch01_reduced_instruction_set"  border="0.5pt solid blue" background-color="#E0E0E0">...</fo:block>
	  <fo:block id="toc...ch01_reduced_instruction_set" space-before.minimum="0.5em" space-before.optimum="1em" space-before.maximum="2em" space-after.minimum="0.5em" space-after.optimum="1em" space-after.maximum="2em" border="0.5pt solid blue" background-color="#E0E0E0">...</fo:block>
	  <fo:block text-align="left" font-size="9pt" font-family="Microsoft YaHei,Cambria Math" font-weight="normal" start-indent="0.0in" end-indent="0.0in"/>
	  <fo:block id="idp8622056"  border="0.5pt solid blue" background-color="#E0E0E0">...</fo:block>
	  <fo:block id="idp8624312"  border="0.5pt solid blue" background-color="#E0E0E0">...</fo:block>
</fo:flow>

就变成了这样

all block content added border - 1

all block content added border - 2

all block content added border - 3

如此,实际上,还是很难看的,没有实现,针对单个的page页面去添加边框(和背景色)的效果。

 

【总结】

目前看来,pdf(fo)中,不支持单个的page页面级别的,去添加边框。

只能针对某一部分内容(内部都是对应的是fo:block),比如标题,章节的内容等等,去添加边框。

总体的效果,很不好,无法实现最初目的。

转载请注明:在路上 » 【未解决】给docbook生成的pdf中每页都添加上边框

发表我的评论
取消评论

表情

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

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

网友最新评论 (4)

  1. hello,crifan,请问如何用docbook添加文章封面?
    mona11年前 (2013-08-26)回复
    • 你说的封面 指的是什么? 想要实现什么样的效果?
      crifan11年前 (2013-08-27)回复
      • 就是在生成的PDF文档首页,插入一张底图,像书本杂志的外观一样。
        mona11年前 (2013-08-27)回复
        • 没弄过。 感觉应该是和自定义titlepage有关。 所以,你可以去: 用google搜: docbook titlepage 可以找到官网的解释: http://www.sagehill.net/docbookxsl/HTMLTitlePage.html 教你如何自定义titlepage的。 自己尝试,想办法,能否在最开始,再添加一页,然后加上你的图片。 自己试试吧,我没弄过,只能帮你到这了。
          crifan11年前 (2013-08-27)回复
91 queries in 0.183 seconds, using 22.09MB memory