I'm using XSL-FO to generate PDF documents with one or more pages. However, if my document has one page I want to hide the {pageNumber}/{totalPage}
(the red rectangle area in the below picture), and only display when {totalPage} > 1
. How do I do that?
Asked
Active
Viewed 125 times
1 Answers
2
- Use a different
fo:simple-page-master
for the single page that uses a differentregion-name
for itsfo:region-after
. - Add an
fo:page-sequence-master
that selects the newfo:simple-page-master
for the single page usingpage-position="only"
. (See XSL-FO Different header/footer depending on page-position, https://stackoverflow.com/a/58343013/4092205, and https://www.w3.org/TR/xsl11/#page-position.) - When you generate the
fo:static-content
that you direct to thefo:region-after
for regular pages, generate anotherfo:static-content
without thefo:page-number
and direct that to thefo:region-after
for thefo:simple-page-master
for the single page. - When the formatter works out that the document fits on a single page, it will use the
fo:simple-page-master
for the single page, and that page will use thefo:static-content
that has aflow-name
that matches theregion-name
of itsfo:region-after
.
So that's a few steps, but that's because there's some flexibility in what you can do with fo:page-sequence-master
selecting different page masters.

Tony Graham
- 7,306
- 13
- 20
-
Excellent Tony, unbelievable, `page-position="only"` , it works perfect, I spent a whole day to find this solution, thank you so much! – kieuanhvu Nov 05 '21 at 13:34