【问题标题】:Apache FOP: ValidationException: The column-number or number of cells in the row overflows the number of fo:table-columns specified for the tableApache FOP:ValidationException:行中的列数或单元格数溢出为表指定的 fo:table-columns 数
【发布时间】:2016-04-26 22:13:09
【问题描述】:

我在尝试使用 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
Ex-dividend date
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 下载?谢谢

【问题讨论】:

  • 您的示例 FO 不包含任何 fo:table-column,但您的代码表明您将生成两个或更多。你能展示一下带有fo:table-column 的版本吗?

标签: python xml pdf xsl-fo apache-fop


【解决方案1】:

看起来,对于 FOP,您需要为表中的每一列提供一个 fo:table-column,或者您不需要。

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

由于您说您删除了一行并且没有产生fo:table-column,并且由于您似乎也在基于dist_dates 生成fo:table-column 并根据投资组合信息生成fo:table-cell,因此您生成@ 的逻辑似乎是987654328@ 不太对。除非您需要在 fo:table-column 上设置宽度或其他属性,否则省略它们也无妨。

【讨论】:

  • 我认为我们确实需要那些宽度属性
  • 您能否确认基于dist_dates 生成fo:table-column 是否正确? FOP 仍然只进行固定表格布局 (xmlgraphics.apache.org/fop/compliance.html),因此您需要以某种方式设置宽度。如果您为每一列生成一个fo:table-column,那么您应该避免 FOP 错误消息。我不知道 FOP 是否实现它,但您应该能够省略 fo:table-column 并在第一个 fo:table-row 中的至少一些 fo:table-cell 上指定 width 以获得相同的效果(请参阅 w3.org/TR/REC-CSS2/tables.html#width-layout )。
猜你喜欢
  • 2014-07-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-25
  • 1970-01-01
  • 2012-04-05
相关资源
最近更新 更多