XSL-FO 呈现器在页面顶部具有区域主体。我该如何解决?
XSL-FO Render Has Region-Body at Top of Page. How do I fix?
我假设 region-body 应该发生在 region-before 之后,但是一旦我转换为 PDF 就不是这种情况了。
<fo:root>
<fo:layout-master-set>
<fo:simple-page-master master-name="simpleA4" page-height="11in" page-width="8.5in"
margin-left="0.5cm" margin-right="0.5cm">
<fo:region-body />
<fo:region-before region-name="xsl-region-before" extent="10mm"/>
<fo:region-after region-name="xsl-region-after" extent="3cm"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="simpleA4">
<fo:static-content flow-name="xsl-region-before">
<fo:block>
HEADER
</fo:block>
</fo:static-content>
<fo:static-content flow-name="xsl-region-after">
<fo:block>
FOOTER
</fo:block>
</fo:static-content>
<fo:flow flow-name="xsl-region-body">
<fo:block space-after="5mm">
<fo:table>
<fo:table-body>
<fo:table-cell>
<fo:block>
CELL 1
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block />
</fo:table-cell>
<fo:table-cell>
<fo:block />
</fo:table-cell>
<fo:table-cell>
<fo:block />
</fo:table-cell>
</fo:table-body>
</fo:table>
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
这是渲染输出的屏幕截图:
区域后按预期工作。
您还没有为您的 body 区域定义任何页边距,并且页面母版也没有顶部或底部页边距。这就是 body 区域流仅从页面顶部开始的原因。这里有一些建议:
Important: The margins you set for the region-body must be greater than or equal to the extents of the the region-before and region-after (XML.com article)
为您的 body 区域设置上下边距:
<fo:region-body margin-top="10mm" margin-bottom="3cm"/>
XSL-FO 文档
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="simpleA4" page-height="11in" page-width="8.5in"
margin-left="0.5cm" margin-right="0.5cm">
<fo:region-body margin-top="10mm" margin-bottom="3cm"/>
<fo:region-before region-name="xsl-region-before" extent="10mm"/>
<fo:region-after region-name="xsl-region-after" extent="3cm"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="simpleA4">
<fo:static-content flow-name="xsl-region-before">
<fo:block>
HEADER
</fo:block>
</fo:static-content>
<fo:static-content flow-name="xsl-region-after">
<fo:block>
FOOTER
</fo:block>
</fo:static-content>
<fo:flow flow-name="xsl-region-body">
<fo:block space-after="5mm">
<fo:table>
<fo:table-body>
<fo:table-cell>
<fo:block>
CELL 1
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block />
</fo:table-cell>
<fo:table-cell>
<fo:block />
</fo:table-cell>
<fo:table-cell>
<fo:block />
</fo:table-cell>
</fo:table-body>
</fo:table>
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
渲染的 PDF 结果 (FOP)
在线尝试此解决方案here,转换仅复制所有内容,结果可以呈现为 PDF。
我假设 region-body 应该发生在 region-before 之后,但是一旦我转换为 PDF 就不是这种情况了。
<fo:root>
<fo:layout-master-set>
<fo:simple-page-master master-name="simpleA4" page-height="11in" page-width="8.5in"
margin-left="0.5cm" margin-right="0.5cm">
<fo:region-body />
<fo:region-before region-name="xsl-region-before" extent="10mm"/>
<fo:region-after region-name="xsl-region-after" extent="3cm"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="simpleA4">
<fo:static-content flow-name="xsl-region-before">
<fo:block>
HEADER
</fo:block>
</fo:static-content>
<fo:static-content flow-name="xsl-region-after">
<fo:block>
FOOTER
</fo:block>
</fo:static-content>
<fo:flow flow-name="xsl-region-body">
<fo:block space-after="5mm">
<fo:table>
<fo:table-body>
<fo:table-cell>
<fo:block>
CELL 1
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block />
</fo:table-cell>
<fo:table-cell>
<fo:block />
</fo:table-cell>
<fo:table-cell>
<fo:block />
</fo:table-cell>
</fo:table-body>
</fo:table>
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
这是渲染输出的屏幕截图:
区域后按预期工作。
您还没有为您的 body 区域定义任何页边距,并且页面母版也没有顶部或底部页边距。这就是 body 区域流仅从页面顶部开始的原因。这里有一些建议:
Important: The margins you set for the region-body must be greater than or equal to the extents of the the region-before and region-after (XML.com article)
为您的 body 区域设置上下边距:
<fo:region-body margin-top="10mm" margin-bottom="3cm"/>
XSL-FO 文档
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="simpleA4" page-height="11in" page-width="8.5in"
margin-left="0.5cm" margin-right="0.5cm">
<fo:region-body margin-top="10mm" margin-bottom="3cm"/>
<fo:region-before region-name="xsl-region-before" extent="10mm"/>
<fo:region-after region-name="xsl-region-after" extent="3cm"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="simpleA4">
<fo:static-content flow-name="xsl-region-before">
<fo:block>
HEADER
</fo:block>
</fo:static-content>
<fo:static-content flow-name="xsl-region-after">
<fo:block>
FOOTER
</fo:block>
</fo:static-content>
<fo:flow flow-name="xsl-region-body">
<fo:block space-after="5mm">
<fo:table>
<fo:table-body>
<fo:table-cell>
<fo:block>
CELL 1
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block />
</fo:table-cell>
<fo:table-cell>
<fo:block />
</fo:table-cell>
<fo:table-cell>
<fo:block />
</fo:table-cell>
</fo:table-body>
</fo:table>
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
渲染的 PDF 结果 (FOP)
在线尝试此解决方案here,转换仅复制所有内容,结果可以呈现为 PDF。