Marcus Fey
Marcus Fey

Reputation: 1

xsl-fo: remove empty (header/footer-only) page in page-sequence

We use XSL-FO for creating PDFs. Users of our application can select if the want the PDF to contain certain blocks or not. This is implemented using conditions in the XML files.

While the default orientation is portrait, some of these optional blocks require landscape orientation.

Sometimes there is an optional portrait block between two optional landscape blocks.

We consoder portrait to be the default, thus inside every optional landscape block there is an initial </fo:page-sequence> to end the previous portrait block's page sequence followed by a <fo:page-sequence ...> with reference to our landscape master. And the end of the landscape blocks we similarly switch back to portrait because normally there will be a portrait block thereafter.

But that's not always the case because portrait blocks can also be skipped.

We thus sometimes end up with

<fo:page-sequence initial-page-number='1' master-reference='A4-LZ-portrait'>
<!-- content-->
</fo:page-sequence>
<fo:page-sequence initial-page-number='auto' force-page-count='no-force'
                      master-reference='A4-GA-landscape'>
<!-- content-->
</fo:page-sequence>
<fo:page-sequence initial-page-number='1' master-reference='A4-LZ-portrait'>
<!-- NO content, this is just due to switching back to portrait -->
</fo:page-sequence>
<fo:page-sequence initial-page-number='auto' force-page-count='no-force'
                      master-reference='A4-GA-landscape'>
<!-- content-->
</fo:page-sequence>

The "no content" page-sequence causes an empty page. How can we get rid of this page?

Sidenote: There are always headers and footers for pages in any orientation.

Upvotes: 0

Views: 45

Answers (2)

Kevin Brown
Kevin Brown

Reputation: 8877

Please rewiew this:

https://lists.w3.org/Archives/Public/www-xsl-fo/2002Mar/0009.html

No one needs some custom thing to accompish.

Some have posted "use XYZ product" and ... take that as you will. It's a commercial. But I have watched 1000s of commercials in my years, never bought anything.

Upvotes: 0

Tony Graham
Tony Graham

Reputation: 8068

An empty fo:page-sequence is not covered by XSL 1.1.

In general, I would recommend modifying your application so that you don't generate empty fo:page-sequence. However, you can do handle them using Antenna House Formatter because it explicitly allows an empty fo:page-sequence (https://www.antenna.co.jp/AHF/help/en/ahf-ext.html#empty-page-sequence).

XSL formatters can also run an initial XSLT transformation (which might default to using an XSLT 1.0 processor). You could instead write some XSLT to remove the empty fo:page-sequence before formatting.

<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"
     xmlns:axf="http://www.antennahouse.com/names/XSL/Extensions"
     xml:lang="en" font-size="40pt">
  <fo:layout-master-set>
    <fo:simple-page-master master-name="spm">
      <fo:region-body/>
    </fo:simple-page-master>
    <fo:simple-page-master master-name="landscape"
               size="A4 landscape"
               background-color="lightyellow">
      <fo:region-body/>
    </fo:simple-page-master>
  </fo:layout-master-set>
  <fo:page-sequence master-reference="spm">
    <fo:flow flow-name="xsl-region-body">
      <fo:block>Hello, world.</fo:block>
    </fo:flow>
  </fo:page-sequence>
  <fo:page-sequence master-reference="landscape">
    <fo:flow flow-name="xsl-region-body">
      <fo:block>Landscape 1.</fo:block>
    </fo:flow>
  </fo:page-sequence>
  <fo:page-sequence master-reference="spm" />
  <fo:page-sequence master-reference="landscape">
    <fo:flow flow-name="xsl-region-body">
      <fo:block>Landscape 2.</fo:block>
    </fo:flow>
  </fo:page-sequence>
</fo:root>

Screenshot of three pages in Antenna House Formatter GUI

Upvotes: 0

Related Questions