Cannot do horizontal table span when cell contains an image

Issue #118 new
Anonymous created an issue

I'm trying to create a table that is two rows by two columns with the top left cell containing an image and spanning across the whole top row. However, when I try to run this code:

from reportlab.lib.units import inch
from reportlab.platypus import BaseDocTemplate, Image, Table, PageTemplate, Frame

my_image = Image('my_image.jpg', width=2*inch, height=2*inch)
table_style = [('SPAN', (0, 0), (-1, 0))]
image_table = Table([[my_image, ''], ['sample', 'text']], style=table_style)

doc = BaseDocTemplate('my_test.pdf', pageTemplates=[PageTemplate(frames=[Frame(inch, inch, 5*inch, 5*inch)])])
doc.build([image_table])

I get this error:

Traceback (most recent call last):
  File "...", line 10, in <module>
    doc.build(story)
  File "/usr/local/lib/python3.5/dist-packages/reportlab/platypus/doctemplate.py", line 969, in build
    self.handle_flowable(flowables)
  File "/usr/local/lib/python3.5/dist-packages/reportlab/platypus/doctemplate.py", line 834, in handle_flowable
    if frame.add(f, canv, trySplit=self.allowSplitting):
  File "/usr/local/lib/python3.5/dist-packages/reportlab/platypus/frames.py", line 167, in _add
    w, h = flowable.wrap(aW, h)
  File "/usr/local/lib/python3.5/dist-packages/reportlab/platypus/tables.py", line 1184, in wrap
    self._calc(availWidth, availHeight)
  File "/usr/local/lib/python3.5/dist-packages/reportlab/platypus/tables.py", line 641, in _calc
    self._calc_height(availHeight,availWidth,W=W)
  File "/usr/local/lib/python3.5/dist-packages/reportlab/platypus/tables.py", line 565, in _calc_height
    w = max(colpositions[span[2]+1]-colpositions[span[0]],w)
TypeError: unorderable types: NoneType() > float()

If I remove the image (i.e. use Table([['', ''], ['sample', 'text']], style=table_style)) or if I try to do a vertical span instead (i.e. use table_style = [('SPAN', (0, 0), (0, -1))]) everything works as expected. It's just the combination of image and horizontal span that seems to not be working.

Thanks.

Comments (1)

  1. Robin Becker

    I just ran this in latest reportlab code and it seems to work for me. I had to use pythonpowered.gif instead of your image. I tried with a jpg of my own and that also worked. Can you say which version of rl you are using? Also what python, platform etc etc.

  2. Log in to comment