xsl-fo - 如何防止 fo:page-number-citation 换行
问题描述
XSL-FO 处理器 - Apache FOP。
有一个非常简单的带有目录的 xsl-fo:
<?xml version="1.0" encoding="utf-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="simple" page-height="29.7cm" page-width="21cm" margin-top="1cm" margin-bottom="2cm" margin-left="2.5cm" margin-right="2.5cm">
<fo:region-body margin-top="3cm"/>
<fo:region-before extent="3cm"/>
<fo:region-after extent="1.5cm"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="simple">
<fo:flow flow-name="xsl-region-body">
<fo:block>Block with fixed page number:</fo:block>
<fo:block text-align-last="justify">Text text text text text text text text text text text text text text text text text text text<fo:leader leader-pattern="dots"/>1</fo:block>
<fo:block> </fo:block>
<fo:block>Block with page-number-citation to existing page:</fo:block>
<fo:block text-align-last="justify">Text text text text text text text text text text text text text text text text text text text<fo:leader leader-pattern="dots"/><fo:page-number-citation ref-id="id_test"/></fo:block>
<fo:block> </fo:block>
<fo:block>Block with page-number-citation to non-existing page:</fo:block>
<fo:block text-align-last="justify">Text text text text text text text text text text text text text text text text text text text<fo:leader leader-pattern="dots"/><fo:page-number-citation ref-id="id_zzz"/></fo:block>
<fo:block id="id_test"/>
</fo:flow>
</fo:page-sequence>
</fo:root>
第一个 ToC 行在页码位置包含固定文本。
第二个 ToC 行包含fo:page-number-citation
第 1 页上的块 ID。
第三个 ToC 行包含fo:page-number-citation
不存在的块的 id。
正如您在图片上看到的,第二个 ToC 行包含换行符。如何预防?看起来 Apache FOP 为页码保留了一些空间(参见第 3 条 ToC 行),但是否可以减少该空间?
更新:
我添加了属性text-align="justify"
:
<?xml version="1.0" encoding="utf-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="simple" page-height="29.7cm" page-width="21cm" margin-top="1cm" margin-bottom="2cm" margin-left="2.5cm" margin-right="2.5cm">
<fo:region-body margin-top="3cm"/>
<fo:region-before extent="3cm"/>
<fo:region-after extent="1.5cm"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="simple">
<fo:flow flow-name="xsl-region-body">
<fo:block-container border-right="1pt solid red">
<fo:block>Block with fixed page number:</fo:block>
<fo:block text-align-last="justify">Text text text text text text text text text text text text text text text text text text text<fo:leader leader-pattern="dots"/>1</fo:block>
<fo:block> </fo:block>
<fo:block>Block with page-number-citation to existing page:</fo:block>
<fo:block text-align-last="justify">Text text text text text text text text text text text text text text text text text text text<fo:leader leader-pattern="dots"/><fo:page-number-citation ref-id="id_test"/></fo:block>
<fo:block> </fo:block>
<fo:block>Block with page-number-citation to existing page (text-align="justify):</fo:block>
<fo:block text-align-last="justify" text-align="justify">Text text text text text text text text text text text text text text text text text text text<fo:leader leader-pattern="dots"/><fo:page-number-citation ref-id="id_test"/></fo:block>
<fo:block> </fo:block>
<fo:block>Block with page-number-citation to existing page (text-align="justify):</fo:block>
<fo:block text-align-last="justify" text-align="justify">Test1: Text text text text text text text text text text text text text text<fo:leader leader-pattern="dots"/><fo:page-number-citation ref-id="id_test"/></fo:block>
<fo:block> </fo:block>
<fo:block>Block with page-number-citation to existing page (text-align="justify):</fo:block>
<fo:block text-align-last="justify" text-align="justify">Test2: Text text text text text text text text text text text text text text text<fo:leader leader-pattern="dots"/><fo:page-number-citation ref-id="id_test"/></fo:block>
<fo:block> </fo:block>
<fo:block>Block with page-number-citation to existing page (text-align="justify):</fo:block>
<fo:block text-align-last="justify" text-align="justify">Test3: Text text text text text text text text text text text text text text text text<fo:leader leader-pattern="dots"/><fo:page-number-citation ref-id="id_test"/></fo:block>
<fo:block> </fo:block>
<fo:block>Block with page-number-citation to existing page (text-align="justify):</fo:block>
<fo:block text-align-last="justify" text-align="justify">Test4: Text text text text text text text text text text text text text text text text text<fo:leader leader-pattern="dots"/><fo:page-number-citation ref-id="id_test"/></fo:block>
<fo:block> </fo:block>
<fo:block>Block with page-number-citation to existing page (text-align="justify):</fo:block>
<fo:block text-align-last="justify" text-align="justify">Test5: Text text text text text text text text text text text text text text text text text text<fo:leader leader-pattern="dots"/><fo:page-number-citation ref-id="id_test"/></fo:block>
<fo:block> </fo:block>
<fo:block id="id_test"/>
</fo:block-container>
</fo:flow>
</fo:page-sequence>
</fo:root>
解决方案
推荐阅读
- jenkins - With Jenkins Declarative pipeline, how do I set the value of a variable in a stage based on exe output output?
- windows - batch: launch pipenv shell, then run command in the virtual environment
- python - Python无法识别命令,但CMD可以
- ionic-framework - indexOf 对我不起作用。离子
- php - .htaccess url 由 slug 发布
- r - 在 RStudio 中运行时,.First 函数的内容似乎没有被处理
- node.js - Mailjet v3.1 邮件发送失败,错误代码
- sql - 如何在 SSRS/Powerbi 中划分同一列的两行?
- python - 如何创建一个包含空列表的 Python 对象
- python - python中pairplot的单个轴限制