[reportlab-users] Embedding Platypus Story in Canvas
Tim Roberts
timr at probo.com
Tue Nov 6 18:50:07 EST 2007
Rich Shepard wrote:
> On Tue, 6 Nov 2007, Tim Roberts wrote:
>
>> You have two choices.
> ...
>> 2. You can derive your own class from SimpleDocTemplate, and override
>> _startBuild to use the canvas you pass in.
>
> I'm really in a hole. Did this but still no joy. Here's the class:
>
> class MyTemplate(SimpleDocTemplate):
> _invalidInitArgs = ('pageTemplates',)
>
> myCanvas = canvas.Canvas('input_variables.pdf', pagesize=LETTER)
>
> def _startBuild(self, filename='input_variables.pdf',
> canvasmaker=myCanvas):
> self._calc()
> self.canv = canvasmaker(filename or self.filename,
> pagesize=self.pagesize,
> invariant=self.invariant,
> pageCompression=self.pageCompression)
> if self._onPage:
> self.canv.setPageCallBack(self._onPage)
> self.handle_documentBegin()
>
> And in class ProjectReports() I assign
>
> pg = MyTemplate.myCanvas
>
> so all additional references to pg become self.pg. No python errors, but
> still only a one-page report.
Create the canvas outside of the class, and pass it in. So:
class MyTemplate( SimpleDocTemplate ):
def _startBuild( self, filename, canvas ):
self._calc()
self.canv = canvas
self._doSave = 0
if self._onPage:
senf.canv.setPageCallBack(self._onPage)
self.handle_documentBegin()
Then, when you call it, pass in the canvas:
myCanvas = canvas.Canvas( 'input_variables.pdf', pagesize=LETTER )
doc = MyTemplate( None, canvas )
However, if you don't need to override anything, why don't you just let
the template create the canvas and pull it out later?
--
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
More information about the reportlab-users
mailing list