XSL-FO渲染在页面顶部有Region-Body。我该如何解决?

时间:2016-01-05 23:37:53

标签: xml xsl-fo

我假设区域体应该在区域之前发生,但是一旦我转换为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>

以下是渲染输出的屏幕截图:

Example of rendered output

该地区 - 正在按预期工作。

1 个答案:

答案 0 :(得分:2)

您尚未为您的身体区域定义任何边距,而页面母版也没有顶部或底部边距。这就是为什么身体区域流动只是在页面顶部开始的原因。以下是对此的一些建议:

  

重要提示:您为region-body设置的边距必须大于或等于region-before和region-after(XML.com article)的范围

设置身体区域的上下边距:

<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)

  

enter image description here

在线here尝试此解决方案,转换仅复制所有内容,结果可以呈现为PDF。