xsl-fo:两个报告并行,一个是奇数页,另一个是偶数页

时间:2018-02-20 00:31:27

标签: xsl-fo

我想要生成一个PDF,其中一个内容流在奇数页中,另一个内容在偶数页中,因此当您双面打印PDF时,您有一个模板可以编写注释甚至页面。这就是我所拥有的,但它不起作用:

    <?xml version="1.0" encoding="UTF-8"?> 
    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
        <fo:layout-master-set>
            <!-- Odd Pages -->
            <fo:simple-page-master master-name="odd" page-height="297mm" page-width="210mm" margin-left="2mm" margin-right="2mm">
                <fo:region-body region-name="body-odd" margin-top="118mm" margin-bottom="50mm"/>
                <fo:region-before region-name="headerodd" extent="116mm"/>
                <fo:region-after region-name="footerodd" extent="48mm"/>
            </fo:simple-page-master>

            <!-- Even Pages -->
            <fo:simple-page-master master-name="even" page-height="297mm" page-width="210mm" margin-left="2mm" margin-right="2mm">
                <fo:region-body region-name="body-even" margin-top="118mm" margin-bottom="50mm"/>
                <fo:region-before region-name="headereven" extent="116mm"/>
                <fo:region-after region-name="footereven" extent="48mm"/>
            </fo:simple-page-master>

            <fo:page-sequence-master master-name="A4">
                <fo:repeatable-page-master-alternatives>
                    <fo:conditional-page-master-reference master-reference="odd" blank-or-not-blank="any" odd-or-even="odd"/>
                    <fo:conditional-page-master-reference master-reference="even" blank-or-not-blank="any" odd-or-even="even"/>
                </fo:repeatable-page-master-alternatives>
            </fo:page-sequence-master>
        </fo:layout-master-set>

        <fo:page-sequence master-reference="A4">
            <fo:flow flow-name="body-odd">
                <fo:block page-break-after="always">
                    This is an ODD page. Front-page report 1.
                </fo:block>
                <fo:block page-break-after="always">
                    This is an ODD page. Front-page report 1.
                </fo:block>
                <fo:block page-break-after="always">
                    This is an ODD page. Front-page report 1.
                </fo:block>
            </fo:flow>
        </fo:page-sequence>

        <fo:page-sequence master-reference="A4">
            <fo:flow flow-name="body-even">
                <fo:block page-break-after="always">
                    This is an EVEN page. Back-page report 2
                </fo:block>
                <fo:block page-break-after="always">
                    This is an EVEN page. Back-page report 2
                </fo:block>
                <fo:block page-break-after="always">
                    This is an EVEN page. Back-page report 2
                </fo:block>
            </fo:flow>
        </fo:page-sequence>

    </fo:root>

2 个答案:

答案 0 :(得分:0)

您正在创建2个单独的页面序列,第一个序列中的奇数页和第二个序列中的偶数页。 如果你把奇数和偶数放在同一个序列中,你应该得到你想要的。

<fo:page-sequence master-reference="A4">
        <fo:flow flow-name="body-odd">
            <fo:block page-break-after="always">
                This is an ODD page. Front-page report 1.
            </fo:block>
            <fo:block page-break-after="always">
                This is an ODD page. Front-page report 1.
            </fo:block>
            <fo:block page-break-after="always">
                This is an ODD page. Front-page report 1.
            </fo:block>
        </fo:flow>
        <fo:flow flow-name="body-even">
            <fo:block page-break-after="always">
                This is an EVEN page. Back-page report 2
            </fo:block>
            <fo:block page-break-after="always">
                This is an EVEN page. Back-page report 2
            </fo:block>
            <fo:block page-break-after="always">
                This is an EVEN page. Back-page report 2
            </fo:block>
        </fo:flow>
    </fo:page-sequence>

答案 1 :(得分:0)

将备注页面的静态内容放在fo:static-content中,该fo:region-before指向偶数页面的<fo:page-sequence master-reference="A4"> <fo:static-content flow-name="headereven"> <fo:block> This is an EVEN page. Back-page report 2 </fo:block> </fo:static-content> <fo:flow flow-name="body-odd"> <fo:block page-break-after="always"> This is an ODD page. Front-page report 1. </fo:block> <fo:block page-break-after="always"> This is an ODD page. Front-page report 1. </fo:block> <fo:block page-break-after="always"> This is an ODD page. Front-page report 1. </fo:block> </fo:flow> </fo:page-sequence> (或任何其他外部区域):

fo:region-before

这样,您就不需要拥有与您的真实内容相匹配的恰当数量的网页内容。

您可以定位内容,使其显示在页面上的正确位置。如果您将静态内容定向到 <img src="{% static 'test/img/release.png' %}"> ,则不必担心使用正确的范围,因为默认情况下溢出该区域的任何内容都将保持可见。