XSLFO - 显示 header 和页脚

XSLFO - displaying header and footer

正在使用 XSL FO 将 xml 转换为 PDF。我想以下面的格式

显示Header内容
Header Contents

Line 1               Line 1.1
Line 2               Line 1.2
Line 2               Line 1.3

现在,我正在尝试使用以下代码行:

 <fo:block> Line 1 </fo:block> <fo:block>   Line 1.1 </fo:block>
 <fo:block> Line 2 </fo:block> <fo:block>   Line 1.2 </fo:block>
 <fo:block> Line 3 </fo:block> <fo:block>   Line 1.3 </fo:block>

那么看起来像一个表格布局:

        <fo:table width="100%">
            <fo:table-body>
                <fo:table-row>
                    <fo:table-cell>
                        <fo:block> Line 1 </fo:block>
                    </fo:table-cell>
                    <fo:table-cell>
                        <fo:block text-align="right"> Line 1.1 </fo:block>
                    </fo:table-cell>
                </fo:table-row>
                <fo:table-row>
                    <fo:table-cell>
                        <fo:block> Line 2 </fo:block>
                    </fo:table-cell>
                    <fo:table-cell>
                        <fo:block text-align="right"> Line 1.2 </fo:block>
                    </fo:table-cell>
                </fo:table-row>
                <fo:table-row>
                    <fo:table-cell>
                        <fo:block> Line 3 </fo:block>
                    </fo:table-cell>
                    <fo:table-cell>
                        <fo:block text-align="right"> Line 1.3 </fo:block>
                    </fo:table-cell>
                </fo:table-row>
            </fo:table-body>
        </fo:table>

如果你想定位 "Line 1" 对齐到 header 的左边,"Line 1.1" 对齐到 header 的右边,就不需要使用 tabular布局。下面的示例使用 fo:leader object 来完成此要求。

    <fo:static-content flow-name="xsl-region-before" font-size="9pt">
        <fo:block space-before="2mm" space-before.conditionality="retain" space-after="2mm"  border-bottom="2pt solid green">
            <fo:block text-align-last="justify">Line 1<fo:leader leader-length.maximum="100%" leader-pattern="space"/>Line 1.1</fo:block>
            <fo:block text-align-last="justify">Line 2<fo:leader leader-length.maximum="100%" leader-pattern="space"/>Line 1.2</fo:block>
            <fo:block text-align-last="justify">Line 3<fo:leader leader-length.maximum="100%" leader-pattern="space"/>Line 1.3</fo:block>
        </fo:block>
    </fo:static-content>

FOP格式化结果: