[reportlab-users] renderPM 'module' object has no attribute 'saveToFile'

Robin Becker robin at reportlab.com
Mon Jul 10 08:40:56 EDT 2006


Genís Pujol wrote:
> Hello,
> 
>  
> 
> I've just installed reportlab and the PM plugin, but when I try to execute a sample script I found in the documentation, I get the following error:
> 
>  
> 
> < - - - Error message starts here - - - >
> 
> Traceback (most recent call last):
> 
>   File "reportlab.test", line 7, in ?
> 
>     renderPM.saveToFile(d, 'example1.png', 'PNG')
> 
> AttributeError: 'module' object has no attribute 'saveToFile'
> 
> < - - - end of error message - - - >
> 
> Other info:
> 
> Python 2.3.3
> 
> renderPM-1.01-20060710
> 
> ReportLab_1_21
> 
>  
> 
> < - - - - Python script begins here - - - - >
> 
> from reportlab.lib import colors
> 
> from reportlab.graphics.shapes import *
> 
> from reportlab.graphics import renderPM
> 
> d = Drawing(400, 200)
> 
> d.add(Rect(50, 50, 300, 100, fillColor=colors.yellow))
> 
> d.add(String(150,100, 'Hello World', fontSize=18, fillColor=colors.red))
> 
> renderPM.saveToFile(d, 'example1.png', 'PNG')
> 
> < - - - - End of script - - - - >
> 
> Any help will be appreciated,
> 
it's a mis-spelling in one way or another.
renderPM has a drawToFile function with signature


drawToFile(d,fn,fmt='GIF', dpi=72, bg=0xffffff, configPIL=None, 
showBoundary=rl_config._unset_)

and a save method which is actually the same.

The PMCanvas object from renderPM has a saveToFile method with arguments 
filename,format and drawings themselves have a save method which allows you to 
convert a drawing without using a specific renderer.


So you can do

renderPM.drawToFile(d, 'example1.png', 'PNG')
renderPM.save(d, 'example1.png', 'PNG')

or

d.save(formats=['PNG'],outDir='.',fnRoot='example1')

the latter is more useful if saving more than one format eg PDF & PNG. Also 
there's a useful py format which saves the low level drawing operations needed 
to create your drawing.
-- 
Robin Becker


More information about the reportlab-users mailing list