[reportlab-users] Page background image with Platypus?
Erik Wickstrom
erik at erikwickstrom.com
Wed Oct 24 15:31:15 EDT 2007
That did the trick, Robin!
On 10/24/07, Robin Becker <robin at reportlab.com> wrote:
> Erik Wickstrom wrote:
> > I tried this approach - but I'm starting to get other problems:
> >
> > Traceback (most recent call last):
> > File "/usr/local/lib/python2.4/site-packages/django/core/handlers/base.py"
> > in _real_get_response
> > 81. response = callback(request, *callback_args, **callback_kwargs)
> > File "/root/journal/gazette/views.py" in some_view
> > 101. doc.build(elements)
> >
> > AttributeError at /gazette/test/
> > GazettePageTemplate instance has no attribute 'build'
> >
> > This is my class so far:
> > class GazettePageTemplate(PageTemplate):
> > def __init__(self, id, pageSize=defaultPageSize):
> > self.pageWidth = pageSize[0]
> > self.pageHeight = pageSize[1]
> > frame1 = Frame(inch,
> > 3*inch,
> > self.pageWidth - 2*inch,
> > self.pageHeight - 518, id='cover')
> > PageTemplate.__init__(self, id, [frame1]) # note lack of onPage
> >
> > def beforeDrawPage(self, canv):
> > self.canv.drawImage('/root/journal/gazette/paper1.png',0,0,8.5*inch,11*inch)
> >
> > def some_view(request):
> > response = HttpResponse(mimetype='application/pdf')
> > response['Content-Disposition'] = 'attachment; filename=gorilla-gazette.pdf'
> >
> > buffer = StringIO()
> >
> > # Our container for 'Flowable' objects
> > elements = []
> >
> > # A large collection of style sheets pre-made for us
> > styles = getSampleStyleSheet()
> >
> > # A basic document for us to write to 'hello_platypus.pdf'
> > #doc = SimpleDocTemplate(buffer)#'hello_platypus.pdf')
> > doc = GazettePageTemplate(buffer)#'hello_platypus.pdf')
> > doc.pagesize=landscape(letter)
> >
> > from reportlab.rl_config import defaultPageSize
> >
> > (MAXWIDTH, MAXHEIGHT) = defaultPageSize
> >
> > image = Image('/root/journal/gazette/paper1.png')
> > print MAXWIDTH
> > print MAXHEIGHT
> > #elements.append(KeepInFrame(MAXWIDTH, MAXHEIGHT, [image]))
> > elements.append(KeepInFrame(11*inch, 19*inch, [image]))
> > # Create two 'Paragraph' Flowables and add them to our 'elements'
> > elements.append(Paragraph("The Platypus", styles['Heading1']))
> > elements.append(Paragraph("Very <i>Special</i>!", styles['Normal']))
> >
> > # Write the document to disk
> > doc.build(elements)
> > # Get the value of the StringIO buffer and write it to the response.
> > pdf = buffer.getvalue()
> > buffer.close()
> > response.write(pdf)
> > return response
> >
> > Shouldn't the build method be inherited from PageTemplate? What am I missing?
> >
> > Thanks!
> > Erik
> ......
>
> the build method is actually on the document not it's page templates. I don't
> know what the intention is, but I guess you should start with
>
> doc = SimpleDocTemplate(buffer)
>
> #and then mess with doc's pagetemplates eg
>
> doc.pageTemplates[:] = [GazettePageTemplate('First')]
>
> #then later
>
> doc.build()
> .......
>
>
> --
> Robin Becker
> _______________________________________________
> 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