Skip to content

Commit adba7e2

Browse files
authored
Merge pull request #2200 from laws-africa/fix-tables
bring back setting rowspans to a max -- FOP complains about empty rows
2 parents e942008 + d2d2e07 commit adba7e2

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

indigo_api/exporters.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,11 +395,18 @@ def resize_tables(self, doc):
395395
""" Ensure that tables have the correct number of columns and rows, otherwise
396396
PDF generation fails.
397397
"""
398-
# there should never be a completely empty row -- check for this first
399398
for table in doc.root.xpath('//a:table', namespaces={'a': doc.namespace}):
399+
# there should never be a completely empty row (FOP constraint)
400+
for empty_row in table.xpath('a:tr[not(a:td|a:th)]', namespaces={'a': doc.namespace}):
401+
table.remove(empty_row)
402+
# a cell can't span more rows than actually come after it (FOP constraint)
400403
for row in table.xpath('a:tr', namespaces={'a': doc.namespace}):
401-
if not row.xpath('a:td|a:th', namespaces={'a': doc.namespace}):
402-
table.remove(row)
404+
actual = len(list(row.itersiblings(f'{{{doc.namespace}}}tr')))
405+
for cell in row.xpath('a:td[@rowspan] | a:th[@rowspan]', namespaces={'a': doc.namespace}):
406+
rowspan = int(cell.get('rowspan', 1))
407+
if rowspan > 1:
408+
# rowspan is the smaller of the current rowspan, and the actual number of rows (plus this one)
409+
cell.set('rowspan', str(min(rowspan, actual + 1)))
403410

404411
matrix = self.map_table(table, doc)
405412

indigo_api/tests/pdf_fixtures/tables/bad_spans_out.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<content>
99
<table eId="att_1__table_2" class="border">
1010
<colgroup><col width="14.285714285714286%"/><col width="14.285714285714286%"/><col width="14.285714285714286%"/><col width="14.285714285714286%"/><col width="14.285714285714286%"/><col width="14.285714285714286%"/><col width="14.285714285714286%"/></colgroup><tr>
11-
<td rowspan="12">
11+
<td rowspan="5">
1212
<p eId="att_1__table_2__p_1">Nature of ownership<br/>or control the<br/>beneficial owner has<br/>in the company ,<br/>whether individually<br/>or jointly*</p>
1313
</td>
1414
<td rowspan="2" colspan="3">
@@ -31,11 +31,11 @@
3131
</td>
3232
</tr>
3333
<tr>
34-
<td rowspan="2" colspan="3" style="width:54.078%">
34+
<td rowspan="1" colspan="3" style="width:54.078%">
3535
<p eId="att_1__table_2__p_6">.A person holds the highest percentage of the issued<br/>shares but does not meet the above<br/>four criteria . <br/>- Directly.........%of shares<br/>-Indirectly.........%of shares</p>
3636
</td>
3737
<td><p/></td><td><p/></td><td><p/></td></tr>
38-
<tr><td><p/></td><td><p/></td><td><p/></td></tr><tr><td><p/></td><td><p/></td><td><p/></td><td><p/></td><td><p/></td><td><p/></td></tr><tr><td><p/></td><td><p/></td><td><p/></td><td><p/></td><td><p/></td><td><p/></td></tr><tr><td><p/></td><td><p/></td><td><p/></td><td><p/></td><td><p/></td><td><p/></td></tr><tr><td><p/></td><td><p/></td><td><p/></td><td><p/></td><td><p/></td><td><p/></td></tr><tr><td><p/></td><td><p/></td><td><p/></td><td><p/></td><td><p/></td><td><p/></td></tr><tr><td><p/></td><td><p/></td><td><p/></td><td><p/></td><td><p/></td><td><p/></td></tr></table>
38+
</table>
3939
<table eId="att_2__table_1" class="border">
4040
<colgroup><col width="55.6701030927835%"/><col width="4.123711340206185%"/><col width="3.092783505154639%"/><col width="6.185567010309278%"/><col width="6.185567010309278%"/><col width="6.185567010309278%"/><col width="6.185567010309278%"/><col width="6.185567010309278%"/><col width="6.185567010309278%"/></colgroup><tr>
4141
<td colspan="4">

0 commit comments

Comments
 (0)