[reportlab-users] memory error

Andy Robinson andy at reportlab.com
Wed Jul 8 15:18:54 EDT 2009


2009/7/8 Robert Robert <robertrobert93 at yahoo.com>:

> Hello All,

> I am creating a pdf file in which I include images. A lot of them. When I

> open the python script with IDLE, the first time it works perfectly. When I

> want to recreate the PDF file I get a memory error as follow;

>

> In string.py"

> return sep.join(words)

> MemoryError


We construct the PDF file in memory. At a certain point, you run out.
We could optimize for specific cases but then somebody would just
decide to put 1000 5Mb images in a PDF where previously they did 500,
and the same would happen elsewhere in the code.

As a very, very rough rule of thumb, we tend to need 10Mb of RAM for
1Mb of PDF output, because there are lots of streams that get
compressed to make the final PDF file.

As another rule of thumb, if you're using jpegs (which just get
inlined in the PDF) then the total PDF size is the size of all the
images, plus 5-10% more for enclosing them.

So, add up the size of images you need to include, decide if it's
reasonable for your system (and if anybody really wants a 100M PDF
file), and then either make several smaller documents, or use
something like PIL to shrink your images to a more appropriate
resolution.

I hope this helps but I doubt it will ;-)


--
Andy Robinson
CEO/Chief Architect
ReportLab Europe Ltd.
Media House, 3 Palmerston Road, Wimbledon, London SW19 1PG, UK
Tel +44-20-8545-1570


More information about the reportlab-users mailing list