I have the following (part of) xsl:fo template
<fo:root font-size="11pt" font-family="Arial">
<fo:layout-master-set>
<fo:simple-page-master master-name="A4-portrait"
page-height="29.7cm" page-width="21.0cm" margin-top="1cm"
margin-left="1.5cm" margin-right="1cm" margin-bottom="1cm">
<fo:region-body />
<fo:region-after region-name="footer" extent="15mm"/>
</fo:simple-page-master>
<fo:simple-page-master master-name="A4-landscape"
page-width="29.7cm" page-height="21.0cm" margin-top="1cm"
margin-left="1cm" margin-right="1cm" margin-bottom="1cm">
<fo:region-body />
<fo:region-after region-name="footer2" display-align="bottom" extent="0cm"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="A4-portrait">
...........
</fo:page-sequence>
<fo:page-sequence master-reference="A4-landscape" font-size="8pt" id="end">
<fo:static-content flow-name="footer2" font-size="7pt" font-family="Arial">
<fo:block text-align="center">
Page <fo:page-number/>/<fo:page-number-citation ref-id="end"/>
</fo:block>
</fo:static-content>
<fo:flow flow-name="xsl-region-body">
........................
</fo:flow>
</fo:page-sequence>
</fo:root>
The first page-sequence generates exactly one page. The second page-sequence generates multiple pages (for example 9), which I want to "decorate" with footers where I can display the page numbers. The problem is - for the last page, <fo:page-number> generates 10, 1 from the first page-sequence + 9 from the second page-sequence; and <fo:page-number-citation ref-id="end"/> generates 9. So, page 10 of 9 sounds like an overflow and it's embarrassing. Can anyone please help?
I hope this helps someone someday, I found the solution. I should've used <fo:page-number-citation-last ref-id="end"/>
Related
I am trying to set a footer only in the first page of a RTF document.
Approach
I defined two regions to show one in the first page and the other in the rest of pages.
Once it is done, I could just remove the second footer text to achieve my goal (the generated rtf document only has two pages).
Result
Unfortunately with the transformation below I am getting the "Rest of pages footer" in both pages. It seems XSL-FO never catches the matching criteria for page-position="first".
I also tried a similar approach with odd-or-even="odd" in the conditional-page-master-reference with the same result.
<fo:root>
<fo:layout-master-set>
<fo:simple-page-master master-name="first"
page-height="29.7cm" page-width="21.0cm" margin-left="2.54cm"
margin-right="2.54cm" margin-top="1cm" margin-bottom="2.54cm">
<fo:region-body margin-top="1.54cm"/>
<fo:region-after region-name="footer-first" extent="2cm" display-align="after"/>
</fo:simple-page-master>
<fo:simple-page-master master-name="rest"
page-height="29.7cm" page-width="21.0cm" margin-left="2.54cm"
margin-right="2.54cm" margin-top="1cm" margin-bottom="2.54cm">
<fo:region-body margin-top="1.54cm"/>
<fo:region-after region-name="footer-rest" extent="2cm" display-align="after" />
</fo:simple-page-master>
<fo:page-sequence-master master-name="document">
<fo:repeatable-page-master-alternatives>
<fo:conditional-page-master-reference page-position="first" master-reference="first" />
<fo:conditional-page-master-reference page-position="rest" master-reference="rest" />
</fo:repeatable-page-master-alternatives>
</fo:page-sequence-master>
</fo:layout-master-set>
<xsl:template match="WC">
<xsl:variable name="id.wc">id_<xsl:value-of select="normalize-space(Id/text())"/>
</xsl:variable>
<fo:page-sequence master-reference="document"
padding-top="1cm" initial-page-number="1">
<fo:static-content flow-name="footer-first">
<fo:block padding-top="10pt" font-size="8">
<fo:inline color="grey">
First page footer
</fo:inline>
</fo:block>
</fo:static-content>
<fo:static-content flow-name="footer-rest">
<fo:block text-align-last="center">Rest of pages footer</fo:block>
</fo:static-content>
<!-- Body continues... -->
FOP's RTF output supports only a single page master. See https://xmlgraphics.apache.org/fop/2.6/output.html#rtf
FWIW, you can get the footers with AH Formatter using the free-but-unsupported Word output option (see https://www.antennahouse.com/microsoft-word-output):
How to create a border in the A4 page and How to make rounded fo:block.
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:fox="http://xmlgraphics.apache.org/fop/extensions">
<fo:layout-master-set>
<fo:simple-page-master master-name="A4" page-height="11.40in" page-width="8.27in" margin-top="0.30in" margin-bottom=".030in" margin-left="0.30in" margin-right="0.30in">
<fo:region-body region-name="body" margin=".30in"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="A4">
<fo:flow flow-name="body">
<fo:block text-align="center" border="1pt" border-style="solid">
How to create rounded border
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
I have tested following XSL-FO file via FOP 2.5.
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:fox="http://xmlgraphics.apache.org/fop/extensions">
<fo:layout-master-set>
<fo:simple-page-master master-name="A4" page-height="11.40in" page-width="8.27in" margin-top="0.30in" margin-bottom=".030in" margin-left="0.30in" margin-right="0.30in">
<fo:region-body region-name="body" margin=".30in"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="A4">
<fo:flow flow-name="body">
<fo:block text-align="center" border="1pt" border-style="solid" fox:border-radius="10pt 15pt">
Hello Word!
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
[The output snapshot]
[Sample command-line]
[Oxygen Transformation Scenario]
[Oxygen 21.1 with FOP 2.3 build result]
fo:region-body can have border properties. See https://www.w3.org/TR/xsl11/#fo_region-body.
Rounded corners are not in the XSL 1.1 Recommendation. However, your XSL formatter probably has an extension for rounded corners:
Antenna House has axf:border-radius and related properties (see https://www.antenna.co.jp/AHF/help/v70e/ahf-ext.html#axf.border-radius).
FOP has fox:border-*-*-radius properties (see https://xmlgraphics.apache.org/fop/2.5/extensions.html#rounded-corners).
I am trying to generate a PDF using FOP.
My requirement-
Page 1 - Header and content
Page 2 - Static page for terms
Page 3 - Overflow from page 1
However, when there is no overflow from page 1, the page 2 is not getting generated. I want the second page to be generated even if there is no overflow from page 1. And, I have a different layout for page 2.
Below is the fo file with layout set-
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:fox="http://xmlgraphics.apache.org/fop/extensions"
xmlns:th="http://www.thymeleaf.org">
<fo:layout-master-set>
<!-- layout for the first page -->
<fo:simple-page-master master-name="first"
th:attr="page-width=${dimensions.width} + 'in',page-height=${dimensions.height} + 'in',margin-right=${rightMargin} + 'in',margin-left=${leftMargin} + 'in'"
margin-top="0pt" margin-bottom="1in">
<fo:region-body region-name="xsl-region-body" margin-top="3.3in" margin-bottom="0.375in"/>
<fo:region-before region-name="stmt-header" margin-top="0.5in"/>
<fo:region-after region-name="stmt-footer"/>
</fo:simple-page-master>
<!-- layout for the other pages -->
<fo:simple-page-master master-name="rest"
th:attr="page-width=${dimensions.width} + 'in',page-height=${dimensions.height} + 'in',margin-right=${rightMargin} + 'in',margin-left=${leftMargin} + 'in'"
margin-top="0pt" margin-bottom="1in">
<fo:region-body margin-bottom="0.375in" margin-top="1in"/>
<fo:region-before region-name="stmt-header-1" margin-top="0.5in"/>
<fo:region-after region-name="stmt-footer"/>
</fo:simple-page-master>
<!-- layout for the other pages -->
<fo:simple-page-master master-name="terms"
th:attr="page-width=${dimensions.width} + 'in',page-height=${dimensions.height} + 'in',margin-right=${rightMargin} + 'in',margin-left=${leftMargin} + 'in'"
margin-top="0pt" margin-bottom="1in">
<fo:region-body margin-top="10in" margin-bottom="0.1in"/>
<fo:region-before region-name="stmt-terms" margin-top="0.5in"/>
<fo:region-after region-name="stmt-footer-1"/>
</fo:simple-page-master>
<fo:page-sequence-master master-name="Statement">
<!--<fo:repeatable-page-master-alternatives>-->
<!--<fo:conditional-page-master-reference master-reference="first" page-position="first"/>-->
<!--<fo:conditional-page-master-reference master-reference="terms" page-position="only"/>-->
<!--<fo:conditional-page-master-reference master-reference="rest" page-position="rest"/>-->
<!--</fo:repeatable-page-master-alternatives>-->
<fo:single-page-master-reference master-reference="first"/>
<fo:single-page-master-reference master-reference="terms"/>
<fo:repeatable-page-master-alternatives>
<fo:conditional-page-master-reference master-reference="rest" page-position="rest"/>
</fo:repeatable-page-master-alternatives>
</fo:page-sequence-master>
</fo:layout-master-set>
<!-- end: defines page layout -->
<!-- actual layout -->
<fo:page-sequence master-reference="Statement" id="stmt">
<fo:static-content flow-name="stmt-header">
<th:block th:include="header-logo :: header-logo"/>
</fo:static-content>
<fo:static-content flow-name="stmt-header-1">
<th:block th:include="header-logo :: header-logo-1"/>
</fo:static-content>
<fo:static-content th:with="footer_margin_left=1.7" flow-name="stmt-footer">
<th:block th:include="footer"/>
</fo:static-content>
<fo:static-content th:with="footer_margin_left=0" flow-name="stmt-footer-1">
<th:block th:include="footer"/>
</fo:static-content>
<fo:static-content flow-name="stmt-terms">
<th:block th:include="stmt_terms :: stmt-terms"/>
</fo:static-content>
<fo:flow flow-name="xsl-region-body">
<th:block th:include="${templateLayoutContent} :: stmt-body"/>
</fo:flow>
</fo:page-sequence>
</fo:root>
Can someone help me out here?
I think you are looking for this: force-page-count="even"
This assures that your page-sequence will always have even pages. In fact there has to be a second page then. If there is no content on the page, you can specify the used page-master and static content by the blank-or-not-blank attribute of the conditional-page-master.
I have the xsl-fo template:
<xsl:template match="/">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master margin-right="1cm"
margin-left="2.7cm" margin-bottom="2cm" margin-top="2cm"
page-width="21.5cm" page-height="29.7cm" master-name="first">
<fo:region-body margin-right="1cm" margin-left="0cm" />
<fo:region-after region-name="xsl-region-after" display-align="before" extent="0.7in"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="first">
<fo:static-content flow-name="xsl-region-after">
<fo:block text-align="center" font-size="10pt">
<fo:page-number />
</fo:block>
</fo:static-content>
<fo:flow flow-name="xsl-region-body">
<xsl:apply-templates select="rootElement" />
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
All works excellent, but first page have a page number.
I do not need number on first page.
Thanks y'all!
You have to create a separate page-sequence-master for the first page, that does not include the page number. Then use a statement like this to specify which master will be used for each page of the book:
<fo:page-sequence-master master-name="chapter">
<fo:repeatable-page-master-alternatives>
<fo:conditional-page-master-reference master-reference="page_first" page-position="first"/>
<fo:conditional-page-master-reference master-reference="page_even" odd-or-even="even"/>
<fo:conditional-page-master-reference master-reference="page_odd" odd-or-even="odd"/>
</fo:repeatable-page-master-alternatives>
</fo:page-sequence-master>
(copied from one of my projects, so you'll have to adapt it to your structure)
I have to generate a pdf using xml and xsl.
On the PDF i need different width for different pages.
How can I achive this?
Thanks and Regards
Krishnan
A complete xsl-fo sample :
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master page-height="10cm" page-width="5cm"
master-name="format1">
<fo:region-body />
</fo:simple-page-master>
<fo:simple-page-master page-height="5cm" page-width="10cm"
master-name="format2">
<fo:region-body/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="format1">
<fo:flow flow-name="xsl-region-body">
<fo:block>Test format 1</fo:block>
</fo:flow>
</fo:page-sequence>
<fo:page-sequence master-reference="format2">
<fo:flow flow-name="xsl-region-body">
<fo:block>Test format 2</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>