[reportlab-users] ReportLab memory error on long PDF creation

Larry Bates larry.bates at websafe.com
Wed Jun 13 12:09:09 EDT 2007


I have written an application that assembles scanned .JPG files into a .PDF for
archival purposes. Since each .JPG file represents a complete scanned page, all
I do is drawInlineImage on to the page (see code below). It seemed to work
flawlessly up until I encountered a document that had 958 pages. My program
went through the loop appending a page for each .JPG file and the blew up with
the following traceback:

Traceback (most recent call last):
File "backscansplit.py", line 1037, in <module>
makedocs()
File "backscansplit.py", line 597, in makedocs
mPDF.close()
File "F:\larry\Python\BQS3ZK~D\makePDF.py", line 115, in close
return
File "C:\Python25\Lib\site-packages\reportlab\pdfgen\canvas.py", line 877, in
save
self._doc.SaveToFile(self._filename, self)
File "C:\Python25\Lib\site-packages\reportlab\pdfbase\pdfdoc.py", line 219, in
SaveToFile
f.write(self.GetPDFData(canvas))
File "C:\Python25\Lib\site-packages\reportlab\pdfbase\pdfdoc.py", line 241, in
GetPDFData
return self.format()
File "C:\Python25\Lib\site-packages\reportlab\pdfbase\pdfdoc.py", line 418, in
format
return File.format(self)
File "C:\Python25\Lib\site-packages\reportlab\pdfbase\pdfdoc.py", line 823, in
format
return string.join(strings, "")
File "C:\Python25\lib\string.py", line 317, in join
return sep.join(words)
MemoryError


My machine has 2Gb of memory and Task Manager says I have 1.5G free physical
memory when program starts. As the program runs creating this PDF, available
physical memory is slowly consumed and reaches approximately 400KB just before
the program errors with traceback.

all that is being done inside the loop is:

self.Canvas.setPageSize(pagesize)
#
# Put the image on the .PDF page
#
self.Canvas.drawInlineImage(im, 0, 0, imHpoints, imVpoints)
#
# End this page
#
self.Canvas.showPage()

im is the PIL Image instance. imHpoints and imVpoints are the height and width
of the image in points that I calculate from the image's pixel information.
pagesize is just (imHpoints, imVpoints). This process works for 200+ page
documents with no errors.

Anything that I can do to work around this?

-Larry





More information about the reportlab-users mailing list