[reportlab-users] Image + StringIO + Platypus(?) = big PDF

david asdrubale at gnx.it
Thu Nov 15 05:10:16 EST 2007


Hi all,

I notice an huge difference on the size of generated PDF when I embed the
same jpeg image from a file or from a StringIO object.

Let me show an example:

-----8<------------------------------------------------

from reportlab.platypus import SimpleDocTemplate, Image

# arbitrary size
size = 271, 180
imgFile = 'img1.jpg'

story = [ Image(imgFile, width = size[0], height = size[1]) ]
doc = SimpleDocTemplate('test-direct.pdf')
doc.build(story)

from cStringIO import StringIO
story = [ Image(StringIO(file(imgFile, 'rb').read()), width = size[0],
height = size[1]) ]
doc = SimpleDocTemplate('test-stringio.pdf')
doc.build(story)

----->8------------------------------------------------

The script output is:

-----8<------------------------------------------------
-rw-r--r-- 1 david david 90661 2007-11-14 18:24 img1.jpg
-rw-r--r-- 1 david david 115589 2007-11-15 10:56 test-direct.pdf
-rw-r--r-- 1 david david 419 2007-11-15 10:56 test.py
-rw-r--r-- 1 david david 469845 2007-11-15 10:56 test-stringio.pdf
----->8------------------------------------------------

$ identify img1.jpg
img1.jpg JPEG 768x512 DirectClass 89kb

$ dpkg --list python-reportlab
ii python-reportlab 2.0dfsg-1


Why is test-strinio.pdf so big? I miss the point?

Thank you




More information about the reportlab-users mailing list