XSL-FO Table fixed height

13,842

In FOP you need to work on the <fo:table-cell individually, for heights, font-size...etc. You need to do the following:

  1. Take your notes on the space you will provide for the table for each page
  2. Calculate the number of rows of the table that can be fitted in that space
  3. In a loop create a new table for each page providing the number of rows that each page would hold
  4. Keep in mind hat the header of the table would only be constructed for the first page only, and the tables of the other pages must be constructed headlessly
Share:
13,842
david
Author by

david

Updated on July 01, 2022

Comments

  • david
    david almost 2 years

    I'm trying to generate a pdf file by using XSL-FO with FOP.

    I want to display a table with a fixed height. The table can go on several pages and I would like it to have the same height on every pages.

    I can't even seem to define a fixed height for the table on a single page.

    I've tried setting the height, min-height, max-height on the table and table-body but nothing seems to be taken into account. I've also tried using different XSL-FO processors without any luck.

    Small sample:

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
        <xsl:template match="/">
            <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
                <fo:layout-master-set>
                    <fo:simple-page-master master-name="simpleA4" page-height="29.7cm" page-width="21cm" margin-top="1cm" margin-bottom="1cm" margin-left="2cm" margin-right="2cm">
                        <fo:region-body margin-bottom="20mm"/>
                        <fo:region-after extent="10mm"/>
                    </fo:simple-page-master>
                </fo:layout-master-set>
                <fo:page-sequence master-reference="simpleA4">
                    <fo:flow flow-name="xsl-region-body">
                        <fo:block>
                            <fo:table table-layout="fixed" width="100%" height="10cm" border-style="solid" border-width="0.02cm">
                                <fo:table-column column-width="20%"/>
                                <fo:table-column column-width="20%"/>
                                <fo:table-column column-width="60%"/>
                                <fo:table-body>
                                    <fo:table-row>
                                        <fo:table-cell>
                                            <fo:block>Col1</fo:block>
                                        </fo:table-cell>
                                        <fo:table-cell>
                                            <fo:block>Col2</fo:block>
                                        </fo:table-cell>
                                        <fo:table-cell>
                                            <fo:block>Col3</fo:block>
                                        </fo:table-cell>
                                    </fo:table-row>
                                </fo:table-body>
                            </fo:table>
                        </fo:block>
                    </fo:flow>
                </fo:page-sequence>
            </fo:root>
        </xsl:template>
    </xsl:stylesheet>