Apache FOP:ValidationException:行中的列号或单元格数溢出了为 table 指定的 fo:table 列数

Apache FOP: ValidationException: The column-number or number of cells in the row overflows the number of fo:table-columns specified for the table

我在尝试使用 xml:

呈现 pdf 文件时收到神秘的错误消息
Exception at /url/
('Unable to generate PDF.', b'Exception\norg.apache.fop.apps.FOPException: org.apache.fop.fo.ValidationException: 
The column-number or number of cells in the row overflows the number of fo:table-columns specified for the table. 
(See position 31:15)\njavax.xml.transform.TransformerException: org.apache.fop.fo.ValidationException: 
The column-number or number of cells in the row overflows the number of fo:table-columns specified for the table. (See position 31:15)\n\n')

我唯一要更改的是 <column name="Record date&#10;Ex-dividend date&#10;Payable Date" size="4.2cm"></column>。这与在 Perl 中制作 pdf 的格式相匹配,并且删除该列行修复了 pdf 并且它可以工作。

{% block pages %}
<schedule_page>
    <columns>
        <column name="Record date&#10;Ex-dividend date&#10;Payable Date" size="4.2cm"></column>
        {% for date_set in dist_dates %}
        <column name="{{ date_set.record_date|date:'j-M' }}&#10;{{ date_set.ex_date|date:'j-M' }}&#10;{{ date_set.pay_date|date:'j-M' }}" size="1.675cm" margin="0.1cm"></column>
        {% endfor %}
    </columns>
    <data>
        {% regroup portfolios by group as portfolio_groups %}
        {% for portfolio_group in portfolio_groups %}
        <group name="{{ portfolio_group.grouper }}">
            {% for portfolio in portfolio_group.list %}
            <fund name="{{ portfolio.name }}">
                {% for dist in portfolio.distributions %}
                    <cell value="{{ dist.value }}" {% if dist.value %}margin="0.1cm"{% endif %} ></cell>
                {% endfor %}
            </fund>
            {% endfor %}
        </group>
        {% endfor %}
    </data>
</schedule_page>
{% endblock %}

pdf 之前的 fo 文件如下所示:

<?xml version="1.0" encoding="UTF-8"?>

<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="letter-landscape" page-height="21.59cm" page-width="27.94cm" margin-top="1.0cm" margin-bottom="0.5cm" margin-left="0.97cm" margin-right="0.97cm">
<fo:region-body margin-top="3.5cm" margin-bottom="1.0cm"/>
<fo:region-before extent="4.0cm"/>
<fo:region-after extent="1.0cm"/>
</fo:simple-page-master>
<fo:page-sequence-master master-name="DistributionPage">
<fo:repeatable-page-master-reference master-reference="letter-landscape"/>
</fo:page-sequence-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="DistributionPage">
<fo:static-content flow-name="xsl-region-before">
<fo:table font-size="8pt" font-family="TradeGothicCondensed" border-collapse="separate" table-layout="fixed">
<fo:table-body>
<fo:table-row>
<fo:table-cell margin-bottom="8pt" number-columns-spanned="0">
<fo:block font-weight="bold" font-size="24pt" font-family="TradeGothicCondensed" text-align="left">Distributions</fo:block>
</fo:table-cell>
<fo:table-cell margin-bottom="8pt" vertical-align="top" text-align="right" number-columns-spanned="0">
<fo:block space-after="8pt" margin-bottom="8pt" vertical-align="top">
<fo:external-graphic content-width="1.5in" src="url(static/logo.jpg)"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell>
<fo:block/>
</fo:table-cell>
<fo:table-cell padding-bottom="4pt" margin-bottom="4pt" padding-left="4pt" number-columns-spanned="0">
<fo:block padding-bottom="4pt" margin-bottom="4pt" margin-left="4pt" padding-left="4pt" text-align="center" border-bottom-color="black" border-bottom-width="0.7pt" border-bottom-style="solid">

                        Estimated
                    </fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row/>
<fo:table-row>
<fo:table-cell border-top-color="black" border-top-width="0.7pt" border-top-style="solid">
<fo:block/>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:static-content>
<fo:static-content flow-name="xsl-region-after">
<fo:table padding-top="0.1cm" font-size="8pt" font-family="TradeGothicCondensed" border-collapse="separate" table-layout="fixed">
<fo:table-body>
<fo:table-row>
<fo:table-cell>
<fo:block line-height="10pt" font-size="8pt" text-align="left">Our disclaimer.</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block vertical-align="bottom" line-height="10pt" font-family="TradeGothicCondensed" font-size="8pt" text-align="right">
            Page
            <fo:page-number/> /
            <fo:page-number-citation ref-id="last-page"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:static-content>
<fo:flow flow-name="xsl-region-body">
<fo:table font-size="8pt" font-family="TradeGothicCondensed" border-collapse="separate" table-layout="fixed">
<fo:table-body font-family="TradeGothicCondensed">
<fo:table-row>
<fo:table-cell>
<fo:block font-weight="bold" font-size="14pt" font-family="TradeGothicCondensed" text-align="left" number-columns-spanned="0"/>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell>
<fo:block line-height="13pt" font-weight="bold">A portfolio name</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell display-align="after">
<fo:block line-height="12pt" padding-left="3pt" vertical-align="top" text-align="left">A portfolio name</fo:block>
</fo:table-cell>
</fo:table-row>
...etc...

为什么添加这一行会破坏我的 pdf 下载?谢谢

看起来,对于 FOP,table 中的每一列都需要一个 fo:table-column,或者您需要 none。

XSL 1.1 Recommendation 并不要求,AFAICT,但它也没有说明列数不匹配会发生什么。

因为你说你删除了一行并且没有生成 fo:table-column,而且你似乎也在根据 dist_dates 生成 fo:table-column 并根据投资组合生成 fo:table-cell信息,您生成 fo:table-column 的逻辑似乎不太正确。除非您需要 fo:table-column 上设置的宽度或其他属性,否则忽略它们也没有坏处。