XSL-FO分页符取决于上一页的完整性

时间:2016-07-28 14:01:10

标签: xsl-fo apache-fop

如果上一页内容仅以>页面高度的60%结束,我需要在XSL-FO中插入分页符。例如,如果页面上的文字有一个'占据页面高度的30%,然后下一部分的文本在前一个文本的继续上放在此页面上。否则,将创建新页面。 是否有可能在FOP中?

3 个答案:

答案 0 :(得分:2)

简短的回答是你不能。 XSL FO和相应的格式化程序是为批处理操作而设计的,而不是进行预测(或后视)操作来做出决策,特别是如果这些决策取决于页面位置。在正常的批量格式化操作中,您必须将您的思维过程限制在应该保持在一起的内容和不应该保留的内容。你开始思考的那一刻"如果内容超过页面的X%,我希望在这里有条件的分页符#34;你是偏离轨道和产品"开箱即用"不符合这样的要求。这些通常是多传递格式化引擎的要求,其性质要慢得多。

您可以完成任务,但只能通过集成到流程中的自定义编程来完成。您可以在此链接的位置进行更多调查,其中一些人在格式化过程中扩展了与格式化程序交互的功能:https://www.w3.org/community/ppl/wiki/XSLTExtensions

恕我直言,如果您想要一个能够执行的解决方案,那么您需要提前决定如何适应内容,而不是尝试做依赖于&#34的事情;我走了多少页面。&# 34;

答案 1 :(得分:1)

您可以尝试将page-sequence-master与simple-page-master s结合使用。

示例1(使用页脚):

<fo:simple-page-master master-name="a4_rest" page-width="21cm" page-height="297mm" margin-top="{$page_margin_top}" margin-left="{$page_margin_left}" margin-right="{$page_margin_right}" margin-bottom="{$page_margin_bottom}">
    <fo:region-body/>
</fo:simple-page-master>
<fo:simple-page-master master-name="a4_footer" page-width="21cm" page-height="297mm" margin-top="{$page_margin_top}" margin-left="{$page_margin_left}" margin-right="{$page_margin_right}" margin-bottom="{$page_margin_bottom}">
    <fo:region-body margin-bottom="{$footer_distance}"/>
    <fo:region-after extent="{$footer_distance}"/>
</fo:simple-page-master>

<fo:page-sequence-master master-name="firstPage60Percent">
    <fo:repeatable-page-master-alternatives>
        <fo:conditional-page-master-reference page-position="first" master-reference="a4_footer"/>
        <fo:conditional-page-master-reference page-position="any" master-reference="a4_rest"/>
    </fo:repeatable-page-master-alternatives>
</fo:page-sequence-master>

您需要使用master-reference =&#34; firstPage60Percent&#34;页序列中的选项。 因此,您需要在名为&#34; a4_footer&#34;的简单页面主文件中设置以下选项:

将footer_distance设置为30%-page-margin-bottom

或者

将page-margin-bottom设置为30%-footer_distance。

瞧。

但是,你的下一部分是什么?在块容器上,你可以使用keep-together =&#34; always&#34;或&#34;页内&#34;选项,因此如果此页面上没有更多空间,它可以放到下一页。等等我不知道你的文件。如果您无法解决此问题,需要更多信息。

答案 2 :(得分:0)

AH 格式化程序有一个 axf:keep-together-within-dimension 扩展名,用于指定“保持在一起”将适用的高度。 (见https://www.antenna.co.jp/AHF/help/v70e/ahf-ext.html#axf.keep-together-within-dimension

如果当前页面上的可用高度不到 40%,这样的事情应该强制分页:

<fo:block keep-together.within-page="always" axf:keep-together-within-dimension="40vh">

请参阅 https://www.antennahouse.com/xsl-fo-samples 处的“XSL-FO 示例”页面中的“限制保持在一起应用的高度”示例