File tree Expand file tree Collapse file tree 2 files changed +13
-6
lines changed
tests/pdf_fixtures/tables Expand file tree Collapse file tree 2 files changed +13
-6
lines changed Original file line number Diff line number Diff line change @@ -395,11 +395,18 @@ def resize_tables(self, doc):
395
395
""" Ensure that tables have the correct number of columns and rows, otherwise
396
396
PDF generation fails.
397
397
"""
398
- # there should never be a completely empty row -- check for this first
399
398
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)
400
403
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 )))
403
410
404
411
matrix = self .map_table (table , doc )
405
412
Original file line number Diff line number Diff line change 8
8
<content >
9
9
<table eId =" att_1__table_2" class =" border" >
10
10
<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 " >
12
12
<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 >
13
13
</td >
14
14
<td rowspan =" 2" colspan =" 3" >
31
31
</td >
32
32
</tr >
33
33
<tr >
34
- <td rowspan =" 2 " colspan =" 3" style =" width:54.078%" >
34
+ <td rowspan =" 1 " colspan =" 3" style =" width:54.078%" >
35
35
<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 >
36
36
</td >
37
37
<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 >
39
39
<table eId =" att_2__table_1" class =" border" >
40
40
<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 >
41
41
<td colspan =" 4" >
You can’t perform that action at this time.
0 commit comments