[reportlab-users] Flowables
Tim Roberts
timr at probo.com
Tue Jan 15 15:37:39 EST 2008
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.
More information about the reportlab-users
mailing list