howto set xsl fo table height to 100%?

1.3k Views Asked by At

I have created a pdf template with a table.

The table has a border; after rendering all the data, the content covers only half of the page, so the table border covers only the content.
But I want the table border to cover the entire page regardless of the height of the content, like this:

expected output

  • I have tried to set height of table to 100%, but no luck.
  • I have also tried to put block-progression-dimension.optimum="100%" on last table cell; let me know if that's the right place
         <fo:page-sequence master-reference="A4-portrait">
            <fo:flow flow-name="xsl-region-body">
               <fo:block font-size="14pt" margin-bottom="11pt" height="100%">
                  <fo:table border-width="1pt" border-style="solid" height="100%" border-color="grey" margin-top="-110pt" font-family="Gotham Narrow A, Gotham Narrow B, Helvetica, Arial, sans-serif">
                     <fo:table-body>
                        <fo:table-row>
                           <fo:table-cell number-columns-spanned="2" margin-left="20pt">
                              <fo:block text-align="left" font-weight="bold" font-size="13pt" color="black" margin-bottom="2pt" margin-top="15pt" margin-left="-5pt">
                                 ${ctx.messages.repairInstructionTitle}      
                              </fo:block>
                              <fo:block text-align="left"  font-size="9pt" color="black">
                                 ${ctx.messages.repairInstructionMessage1}      
                              </fo:block>
                              <fo:block text-align="left"  font-size="9pt" color="black">
                                 ${ctx.messages.repairInstructionMessage2} 
                              </fo:block>
                              <fo:block text-align="left"  font-size="9pt" color="black">
                                 ${ctx.messages.repairInstructionMessage3} 
                              </fo:block>
                           </fo:table-cell>
                        </fo:table-row>
                        <fo:table-row>
                           <fo:table-cell>
                              <fo:table margin-top="10pt" margin-bottom="15pt">
                                 <fo:table-column column-width="50%"/>
                                 <fo:table-column column-width="50%"/>
                                 <fo:table-body>
                                    <fo:table-row>
                                       #if ($ctx.orderData.deliveryAddress.country.isocode == 'US')
                                       <fo:table-cell margin-left="30pt" number-columns-spanned="1">
                                          <fo:block text-align="left" font-weight="bold" font-size="9pt" color="black">
                                             ${ctx.messages.repairQuestionForLocationMainland} 
                                          </fo:block>
                                          <fo:block text-align="left"  font-size="9pt" color="black">
                                             ${ctx.messages.mauijimIncMainland} 
                                          </fo:block>
                                          <fo:block text-align="left"  font-size="9pt" color="black">
                                             ${ctx.messages.repairDepartmentLable} 
                                          </fo:block>
                                          <fo:block text-align="left"  font-size="9pt" color="black">
                                             ${ctx.messages.repairDepartmentMainlandAddressLine1} 
                                          </fo:block>
                                          <fo:block text-align="left"  font-size="9pt" color="black">
                                             ${ctx.messages.repairDepartmentMainlandAddressLine2} 
                                          </fo:block>
                                       </fo:table-cell>
                                       <fo:table-cell margin-left="20pt">
                                          <fo:block text-align="left" font-weight="bold" font-size="9pt" color="black">
                                             ${ctx.messages.repairQuestionForLocationHawaii} 
                                          </fo:block>
                                          <fo:block text-align="left"  font-size="9pt" color="black">
                                             ${ctx.messages.mauijimIncHawaii} 
                                          </fo:block>
                                          <fo:block text-align="left"  font-size="9pt" color="black">
                                             ${ctx.messages.repairDepartmentLable}
                                          </fo:block>
                                          <fo:block text-align="left"  font-size="9pt" color="black">
                                             ${ctx.messages.repairDepartmentHawaiiAddressLine1} 
                                          </fo:block>
                                          <fo:block text-align="left"  font-size="9pt" color="black">
                                             ${ctx.messages.repairDepartmentHawaiiAddressLine2}
                                          </fo:block>
                                       </fo:table-cell>
                                       #end
                                    </fo:table-row>
                                 </fo:table-body>
                              </fo:table>
                           </fo:table-cell>
                        </fo:table-row>
                        <fo:table-row>
                           <fo:table-cell margin-left="15pt" block-progression-dimension.optimum="100%">
                              <fo:block text-align="left"  font-size="13pt" color="black" font-weight="bold">
                                 ${ctx.messages.repairAnyQuestionText}
                              </fo:block>
                              #if (${ctx.orderData.deliveryAddress.country.isocode} == 'US')
                              <fo:block text-align="left"  font-size="9pt" color="black">
                                 ${ctx.messages.repairContactInfo}
                              </fo:block>
                              #end 
                              #if (${ctx.orderData.deliveryAddress.country.isocode} != 'US')  
                              <fo:block text-align="left"  font-size="9pt" color="black">
                                 #set($repairContactInfo = "repairContactInfo")
                                 #set($isocode = $ctx.orderData.deliveryAddress.country.isocode )
                                 #set($addMessage = "$repairContactInfo$isocode")   
                                 ${ctx.messages.getMessage($addMessage)}
                              </fo:block>
                              #end  
                           </fo:table-cell>
                        </fo:table-row>
                     </fo:table-body>
                  </fo:table>
               </fo:block>
            </fo:flow>
         </fo:page-sequence>
2

There are 2 best solutions below

5
On

I am not sure what effect you are trying to achieve. The height="100%" on the fo:table makes it 100% of the height of its containing block, but the fo:block has margin-bottom="11pt", which reduces the height available for the fo:block and, therefore, for the fo:table.

The height="100%" gives the table a fixed height, but the margin-top="-110pt" shifts the table up by 110pt so that I'm currently seeing 110pt of blank space after the table.

If you want something really is 100% of the page height, use height="100pvh". See https://www.antenna.co.jp/AHF/help/en/ahf-ext.html#pvh

(Also, margin-left does not apply to fo:table-cell.)

2
On

From the image of the expected output, it looks like you want to have a border around the main page region, regardless of the actual height of its content.

So, it may be enough to move the definition of the border in the fo:region-body element and remove it from the fo:table; you may also consider removing the table altogether and leaving only the blocks it contains, as it does not seem to have any function other than drawing the border.

A couple of points worth mentioning:

  • strictly speaking, this would not be allowed by the XSL-FO Recommendation ("The values of the padding and border-width traits must be "0"."), but is generally allowed by the formatters (AntennaHouse Formatter allows it);
  • this solution is easy to implement if all pages must have a border around the main region; otherwise, you have to modify your templates so that a page sequence with a bordered region-body is created for the content that needs it, and different page sequences using a page master with not borders are created for the rest of the content.