[reportlab-users] Flowables
Brandon Rich
brich at caseta.com
Tue Jan 15 15:49:24 EST 2008
That seems to work
Thanks for the help
B
-----Original Message-----
From: reportlab-users-bounces at reportlab.com
[mailto:reportlab-users-bounces at reportlab.com] On Behalf Of Tim Roberts
Sent: Tuesday, January 15, 2008 2:38 PM
To: Support list for users of Reportlab software
Subject: Re: [reportlab-users] Flowables
Brandon Rich wrote:
> Here is the code that I am currently using.
>
> def createDoc( self, buffer):
> # Generate the PDF
> doc = SimpleDocTemplate( buffer, pagesize = letter, leftMargin
= 0.5*inch, rightMargin = 0.5*inch, bottomMargin = 1.5*inch )
> contents = [ Spacer( 1, 0.15*inch ) ]
> Template (violation, searchList= [{'name' : 'Tim'}]).respond()
> paragraphStyle = get_stylesheets()['Normal']
> p = Paragraph( Template ,paragraphStyle,None)
> contents.append( p )
> contents.append( PageBreak())
> contents.append( Spacer( 1, 0.15*inch ) )
> doc.build( contents, onFirstPage=self.firstPage,
onLaterPages=self.otherPages )
> return (buffer)
>
> And the error...
>
> File "C:\workspace\pythonlibs\tests\document\pdfutil.py", line 91,
in createDoc
> Template (violation, searchList= [{'name' : 'Tim'}]).respond()
> File
"c:\python25\lib\site-packages\cheetah-2.0-py2.5.egg\Cheetah\Template.py
", line 1151, in __init__
> raise TypeError(reason) TypeError: arg 'source' must be string or
None
>
Right. You have a bit of a misunderstanding here. "Template" is the
name of a class. Your "respond" statement above creates a new Template
object, calls respond() on that object to generate the string, and then
throws away the string. Your Paragraph statement then passes the class,
NOT an object, to the Paragraph class constructor.
You want something like this instead:
doc = SimpleDocTemplate( ... )
contents = [ Spacer( 1, 0.15*inch ) ]
paragraphStyle = get_stylesheets()['Normal']
text = Template( violation, searchList=[{'name' : 'Tim'}]).respond()
p = Paragraph( text, paragraphStyle, None )
...
Or, if you want to substitute other variables:
tmpl = Template( violation, searchList = [{'name': 'Tim'}])
tmpl.otherVariable = 1
p = Paragraph( tmpl.respond(), paragraphStyle, None )
--
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
_______________________________________________
reportlab-users mailing list
reportlab-users at reportlab.com
http://two.pairlist.net/mailman/listinfo/reportlab-users
More information about the reportlab-users
mailing list