问题
I want to generate a PDF having one content flow in odd pages and another in even pages, so when you print the PDF double sided you have a template to write notes even pages. This is what I have but it does not work:
<?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>
回答1:
You're creating 2 separate page sequences, with the odd pages in the first sequence, and the even pages in the second sequence. If you place both odd and even in the same sequence, you should get what you want.
<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>
回答2:
Put the static content for the notes pages in an fo:static-content
that is directed to the fo:region-before
(or any of the other outer regions) of the even page:
<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>
This way, you don't need to have exactly the right number of pages worth of note content to match your real content.
You can position the content so that it shows up at the correct position on the page. If you direct the static content to fo:region-before
, you shouldn't have to worry about using the correct extent since any content that overflows the region will remain visible by default.
来源:https://stackoverflow.com/questions/48876221/xsl-fo-two-reports-en-parallel-one-in-odd-pages-another-in-even-pages