[reportlab-users] Memory consumption of a "simple" document seems excessive
Hancock, David (DHANCOCK)
reportlab-users@reportlab.com
Tue, 6 Jan 2004 18:24:19 -0500
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
------_=_NextPart_001_01C3D4AC.35608FD0
Content-Type: text/plain
I'm new to ReportLab--please be gentle...I'd be grateful for any ideas about
my problem.
I am trying to import a GIF image (about 1700x1100 pixels) into a landscape
8.5x11 pagesize PDF. Using the following code, I can reliably eat up 1GB of
RAM and still not get finished. I've had to kill the job at about 1GB
because there are other users on this machine and they'd like not to keep
getting swapped out. Can anyone see what my problem might be? If I comment
out the img stuff, the document builds fine.
I've looked at the FAQ and Googled for "reportlab memory consumption" but
couldn't find anything relevant.
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Image
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.rl_config import defaultPageSize
from reportlab.lib.units import inch
import Image as ImageLib
styles = getSampleStyleSheet()
Title = "My Custom Doc!"
pageinfo = "Landscape Example"
def myPage(canvas, doc):
canvas.saveState()
canvas.setFont('Times-Roman', 9)
canvas.drawString(inch, 0.75 * inch, "Page %d %s" % (doc.page,
pageinfo))
canvas.restoreState()
def go():
doc = SimpleDocTemplate('img.pdf', pagesize=(792.0, 612.0))
doc = SimpleDocTemplate('img.pdf')
Story = [Spacer(1, 0.1*inch)]
style = styles['Normal']
img = Image('fullsize.gif')
img.hAlign = 'CENTER'
Story.append(img)
Story.append(Spacer(1, 0.1*inch))
doc.build(Story, onFirstPage=myPage)
go()
Cheers!
--
David Hancock | dhancock@arinc.com | 410-266-4384
------_=_NextPart_001_01C3D4AC.35608FD0
Content-Type: text/html
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Dus-ascii">
<META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version =
5.5.2653.12">
<TITLE>Memory consumption of a "simple" document seems =
excessive</TITLE>
</HEAD>
<BODY>
<P><FONT SIZE=3D2 FACE=3D"Arial">I'm new to ReportLab--please be =
gentle...I'd be grateful for any ideas about my problem.</FONT>
</P>
<P><FONT SIZE=3D2 FACE=3D"Arial">I am trying to import a GIF image =
(about 1700x1100 pixels) into a landscape 8.5x11 pagesize PDF. =
Using the following code, I can reliably eat up 1GB of RAM and still =
not get finished. I've had to kill the job at about 1GB because =
there are other users on this machine and they'd like not to keep =
getting swapped out. Can anyone see what my problem might =
be? If I comment out the img stuff, the document builds =
fine.</FONT></P>
<P><FONT SIZE=3D2 FACE=3D"Arial">I've looked at the FAQ and Googled for =
"reportlab memory consumption" but couldn't find anything =
relevant.</FONT>
</P>
<P><FONT SIZE=3D2 FACE=3D"Courier New">from reportlab.platypus import =
SimpleDocTemplate, Paragraph, Spacer, Image</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">from reportlab.lib.styles =
import getSampleStyleSheet</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">from reportlab.rl_config import =
defaultPageSize</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">from reportlab.lib.units import =
inch</FONT>
</P>
<P><FONT SIZE=3D2 FACE=3D"Courier New">import Image as ImageLib</FONT>
</P>
<P><FONT SIZE=3D2 FACE=3D"Courier New">styles =3D =
getSampleStyleSheet()</FONT>
</P>
<P><FONT SIZE=3D2 FACE=3D"Courier New">Title =3D "My Custom =
Doc!"</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">pageinfo =3D "Landscape =
Example"</FONT>
</P>
<P><FONT SIZE=3D2 FACE=3D"Courier New">def myPage(canvas, doc):</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New"> =
canvas.saveState()</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New"> =
canvas.setFont('Times-Roman', 9)</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New"> =
canvas.drawString(inch, 0.75 * inch, "Page %d %s" % =
(doc.page, pageinfo))</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New"> =
canvas.restoreState()</FONT>
</P>
<P><FONT SIZE=3D2 FACE=3D"Courier New">def go():</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New"> doc =3D =
SimpleDocTemplate('img.pdf', pagesize=3D(792.0, 612.0))</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New"> doc =3D =
SimpleDocTemplate('img.pdf')</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New"> Story =3D =
[Spacer(1, 0.1*inch)]</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New"> style =3D =
styles['Normal']</FONT>
</P>
<P><FONT SIZE=3D2 FACE=3D"Courier New"> img =3D =
Image('fullsize.gif')</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New"> img.hAlign =
=3D 'CENTER'</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New"> =
Story.append(img)</FONT>
</P>
<P><FONT SIZE=3D2 FACE=3D"Courier New"> =
Story.append(Spacer(1, 0.1*inch))</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New"> =
doc.build(Story, onFirstPage=3DmyPage)</FONT>
</P>
<P><FONT SIZE=3D2 FACE=3D"Courier New">go()</FONT>
</P>
<P><B><FONT SIZE=3D2 FACE=3D"Arial">Cheers!</FONT></B>
<BR><FONT SIZE=3D2 FACE=3D"Arial">--</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">David Hancock | dhancock@arinc.com | =
410-266-4384</FONT>
</P>
</BODY>
</HTML>
------_=_NextPart_001_01C3D4AC.35608FD0--