如何计算<fo:region-before />身高?

How to calculate the <fo:region-before /> height?

在我的 pdf 文档中,我希望一些数据在所有页面上重复,所以我将它们放在 <fo:region-before/> 中。这就导致了区域的高度不固定。我想计算这个区域的高度,把 <fo:region-body/> 的数据放在合适的位置,但我不知道该怎么做?这是我的代码:

<#assign imageBorderWidth=0.4/>
<#assign logoHeight=0.5/>
<#assign regionAfterBlockHeight=0.22/>
<#assign regionAfterHeight=regionAfterBlockHeight * 4/>

<#setting locale="en_US">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" font-family="ArialUni, ArialUniBold, ArialUniItalic" font-size="10pt">
    <fo:layout-master-set>
        <fo:simple-page-master master-name="letter-portrait" page-width="8.5in" page-height="11in"
                               margin-top="0" margin-bottom="0" margin-left="0in" margin-right="0in">
            <fo:region-body margin-top="5in" margin-bottom="${regionAfterHeight}in"
                            margin-left="${imageBorderWidth}in" margin-right="${imageBorderWidth}in" background-color="yellow"/>
            <fo:region-before extent="2in" />
            <fo:region-after extent="${regionAfterHeight}in"/>
        </fo:simple-page-master>
    </fo:layout-master-set>

    <fo:page-sequence master-reference="letter-portrait" id="mainSequence">
        <fo:static-content flow-name="xsl-region-before">
            <fo:block-container absolute-position="absolute" top="0" left="0">
                <fo:block>
                    <fo:external-graphic src="${backgroundLocation.getLocation()}" content-height="11in" content-width="8.5in" scaling="non-uniform"/>
                </fo:block>
            </fo:block-container>
            <#--Header Hóa đơn GTGT, logo, mẫu số-->
            <fo:table table-layout="fixed" width="100%">
                <fo:table-body>
                    <fo:table-row>
                        <fo:table-cell padding="0.5in 0.5in 0in 0.5in" text-align="center" width="2.5in">
                            <fo:block>
                                <#if logoLocation?has_content>
                                    <fo:external-graphic src="${logoLocation.getLocation()}" content-width="2in" content-height="${logoHeight}in" scaling="non-uniform"/>
                                <#else >
                                    <fo:leader />
                                </#if>
                            </fo:block>
                        </fo:table-cell>
                        <fo:table-cell text-align="center" width="3.5in" padding-top="${imageBorderWidth}in" display-align="center ">
                            <fo:block-container height="0.34in">
                                <fo:block font-size="14pt" font-family="ArialUniBold" text-align="center">
                                    HÓA ĐƠN GIÁ TRỊ GIA TĂNG
                                </fo:block>
                            </fo:block-container>
                            <fo:block-container height="0.27in">
                                <fo:block>
                                    <fo:inline font-style="italic">(Bản thể hiện của hóa đơn điện tử)</fo:inline>
                                </fo:block>
                            </fo:block-container>
                            <fo:block-container height="0.27in">
                                <fo:block>
                                    <fo:inline font-style="italic">Ngày tháng năm</fo:inline>
                                </fo:block>
                            </fo:block-container>
                        </fo:table-cell>
                        <fo:table-cell text-align="center" width="2in" padding-top="${imageBorderWidth}in" display-align="center">
                            <fo:table table-layout="fixed" width="100%" >
                                <fo:table-column column-width="30%"/>
                                <fo:table-column column-width="60%"/>
                                <fo:table-body>
                                    <fo:table-row>
                                        <fo:table-cell text-align="left">
                                            <fo:block-container height="0.27in">
                                                <fo:block><fo:inline>Form no:</fo:inline></fo:block>
                                            </fo:block-container>
                                        </fo:table-cell>
                                        <fo:table-cell text-align="left">
                                            <fo:block-container height="0.27in">
                                                <fo:block><fo:inline>01GTKT0/001</fo:inline></fo:block>
                                            </fo:block-container>
                                        </fo:table-cell>
                                    </fo:table-row>
                                    <fo:table-row>
                                        <fo:table-cell text-align="left">
                                            <fo:block-container height="0.27in">
                                                <fo:block><fo:inline>Sign:</fo:inline></fo:block>
                                            </fo:block-container>
                                        </fo:table-cell>
                                        <fo:table-cell text-align="left">
                                            <fo:block-container height="0.27in">
                                                <fo:block><fo:inline>AB/21E</fo:inline></fo:block>
                                            </fo:block-container>
                                        </fo:table-cell>
                                    </fo:table-row>
                                    <fo:table-row>
                                        <fo:table-cell text-align="left">
                                            <fo:block-container height="0.27in">
                                                <fo:block><fo:inline>No:</fo:inline></fo:block>
                                            </fo:block-container>
                                        </fo:table-cell>
                                        <fo:table-cell text-align="left">
                                            <fo:block-container height="0.27in">
                                                <fo:block><fo:inline>000001</fo:inline></fo:block>
                                            </fo:block-container>
                                        </fo:table-cell>
                                    </fo:table-row>
                                </fo:table-body>
                            </fo:table>
                        </fo:table-cell>
                    </fo:table-row>
                </fo:table-body>
            </fo:table>
            <fo:block border-bottom-width="1.5pt" margin="0 ${imageBorderWidth}in 0 ${imageBorderWidth}in " border-bottom-style="solid" margin-top="3mm" border-bottom-color="#b7b7b7" />
            <fo:table table-layout="fixed" width="100%" margin-top="0.1in" font-size="10pt">
                <fo:table-column column-width="80%"/>
                <fo:table-column column-width="20%"/>
                <fo:table-body>
                    <fo:table-row>
                        <fo:table-cell text-align="left" padding-left="${imageBorderWidth}in">
                            <fo:block font-size="15pt" font-family="ArialUniBold" line-height="1.4"><fo:inline>CÔNG TY TNHH QUẢN LÝ NỢ VÀ KHAI THÁC TÀI SẢN NGÂN HÀNG TMCP BẮC Á - CHI NHÁNH THÀNH PHỐ HỒ CHÍ MINH</fo:inline></fo:block>
                        </fo:table-cell>
                        <fo:table-cell text-align="center" number-rows-spanned="5" display-align="before" padding-right="${imageBorderWidth}in">
                            <fo:block>
                                <#assign qrContentWidth=(8.5*0.2) - imageBorderWidth/>
                                <fo:external-graphic src="${qrCodeImgLocation.getLocation()}" content-width="${qrContentWidth}in" content-height="scale-to-fit" scaling="uniform"/>
                            </fo:block>
                        </fo:table-cell>
                    </fo:table-row>
                    <fo:table-row>
                        <fo:table-cell text-align="left" padding-left="${imageBorderWidth}in">
                            <fo:block line-height="1.8"><fo:inline>Taxcode: 0101243150-999</fo:inline></fo:block>
                        </fo:table-cell>
                    </fo:table-row>
                    <fo:table-row>
                        <fo:table-cell text-align="left" padding-left="${imageBorderWidth}in">
                            <fo:block line-height="1.8">
                                <fo:table inline-progression-dimension="auto" table-layout="auto">
                                    <fo:table-column column-number="1" column-width="45pt" />
                                    <fo:table-column column-number="2"/>
                                    <fo:table-body>
                                        <fo:table-row>
                                            <fo:table-cell text-align="left" padding="0">
                                                <fo:block>Address:</fo:block>
                                            </fo:table-cell>
                                            <fo:table-cell text-align="left" padding="0">
                                                <fo:block>Số 36A Phan Đăng Lưu, Phường 05, Quận Phú Nhuận, Thành phố Hồ Chí Minh, Việt Nam</fo:block>
                                            </fo:table-cell>
                                        </fo:table-row>
                                    </fo:table-body>
                                </fo:table>
                            </fo:block>
                        </fo:table-cell>
                    </fo:table-row>
                    <fo:table-row>
                        <fo:table-cell text-align="left" padding-left="${imageBorderWidth}in">
                            <fo:block line-height="1.8"><fo:inline>Phone: 028.38229812</fo:inline></fo:block>
                        </fo:table-cell>
                    </fo:table-row>
                    <fo:table-row>
                        <fo:table-cell text-align="left" padding-left="${imageBorderWidth}in">
                            <fo:block line-height="1.8"><fo:inline>Bank Account:</fo:inline></fo:block>
                        </fo:table-cell>
                    </fo:table-row>
                </fo:table-body>
            </fo:table>
            <fo:block border-bottom-width="1.5pt" margin="0 ${imageBorderWidth}in 0 ${imageBorderWidth}in " border-bottom-style="solid" margin-top="1mm" border-bottom-color="#b7b7b7" />
        </fo:static-content>

        <fo:static-content flow-name="xsl-region-after" font-size="9pt" >
            <fo:table table-layout="fixed" width="100%" >
                <fo:table-column column-width="90%"/>
                <fo:table-column column-width="10%"/>
                <fo:table-body>
                    <fo:table-row>
                        <fo:table-cell text-align="left" padding-left="${imageBorderWidth}in">
                            <fo:block-container height="${regionAfterBlockHeight}in"><fo:block text-align="left">Tra cứu tại Website: https://www.meinvoice.vn/tra-cuu - Mã tra cứu hóa đơn:</fo:block></fo:block-container>
                        </fo:table-cell>
                        <fo:table-cell/>
                    </fo:table-row>
                    <fo:table-row>
                        <fo:table-cell >
                            <fo:block-container height="${regionAfterBlockHeight}in"><fo:block text-align="center">(Cần kiểm tra, đối chiếu khi lập, giao, nhận hóa đơn)</fo:block></fo:block-container>
                        </fo:table-cell>
                        <fo:table-cell/>
                    </fo:table-row>
                    <fo:table-row>
                        <fo:table-cell>
                            <fo:block-container height="${regionAfterBlockHeight}in"><fo:block text-align="center">Phát hành bởi phần mềm MISA meInvoice - Công ty Cổ phần MISA (www.misa.com.vn) - MST: 0101243150</fo:block></fo:block-container>
                        </fo:table-cell>
                        <fo:table-cell padding-right="${imageBorderWidth}in">
                            <fo:block-container height="${regionAfterBlockHeight}in">
                                <fo:block>
                                    <fo:block text-align="right"><fo:page-number/>/<fo:page-number-citation-last ref-id="endContent"/></fo:block>
                                </fo:block>
                            </fo:block-container>
                        </fo:table-cell>
                    </fo:table-row>
                </fo:table-body>
            </fo:table>
        </fo:static-content>

        <fo:flow flow-name="xsl-region-body" >
            <fo:block>aaaaa</fo:block>
            <fo:block>aaaaa</fo:block>
            <fo:block>aaaaa</fo:block>
            <fo:block>aaaaa</fo:block>
            <fo:block>aaaaa</fo:block>
            <fo:block>aaaaa</fo:block>
            <fo:block>aaaaa</fo:block>
            <fo:block>aaaaa</fo:block>
            <fo:block>aaaaa</fo:block>
            <fo:block>aaaaa</fo:block>
            <fo:block>aaaaa</fo:block>
            <fo:block>aaaaa</fo:block>
            .......  
            <fo:block id="endContent">aaaaa</fo:block>
        </fo:flow>
    </fo:page-sequence>
</fo:root>

而我的结果,黄色区域<fo:region-body/>红色矩形<fo:region-before/>,我希望 黄色区域 红色矩形 红色矩形 之后立即在所有页面上重复

最简单的答案是将所有内容都放在 fo:table 中,当前页 header 放在 fo:table-header 中,每个页都重复。

一个更复杂的解决方案是在 XSLT 转换期间使用 https://github.com/pplcg/XSLTExtensions 的打印和页面布局社区组的 XSLT 扩展到 运行 格式化程序以获得 header 内容,以便您可以准确计算出它需要多少高度。但是,<#assign 和其他标记让我认为您可能没有太多访问 XSLT 处理器的权限,并且可能无法将其配置为使用扩展。