[reportlab-users] Page background image with Platypus?
Stephan Diehl
stephan.diehl at gmx.net
Sat Oct 6 03:32:32 EDT 2007
Erik Wickstrom wrote:
> I tried your suggestion, but it just seems to throw more errors. Here
> is a snipet of my code:
>
> from cStringIO import StringIO
> from reportlab.lib.styles import getSampleStyleSheet
> from reportlab.platypus import *
> from reportlab.platypus.flowables import KeepInFrame
> from reportlab.platypus import Image
> from reportlab.pdfgen import canvas
> from reportlab.lib.pagesizes import letter, portrait, landscape
> from reportlab.lib.units import inch
> ......
> ......
> from reportlab.rl_config import defaultPageSize
>
> (MAXWIDTH, MAXHEIGHT) = defaultPageSize
>
> image = Image('/root/journal/gazette/paper1.png')
> elements.append (KeepInFrame(MAXWIDTH, MAXHEIGHT, image))
^^^^^^
I believe this line should be
elements.append (KeepInFrame(MAXWIDTH, MAXHEIGHT, [image]))
Have you tested with different MAX sizes? Maybe it needs to be smaller
than the page size (I'm guessing here). My guess would be that it can't
be larger than the space that would be filled with text, if it were text.
And, by the way, I'm using reportlab from svn repository.
> # 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)
>
> Am I using KeepInFrame incorrectly?
>
> Thanks!
> Erik
>
> On 10/5/07, *Stephan Diehl* <stephan.diehl at gmx.net
> <mailto:stephan.diehl at gmx.net>> wrote:
>
> Erik Wickstrom wrote:
> > Hi,
> >
> > I'm trying to use an image as a background for my pdf. The image is
> > large enough to cover the page. It seems to work fine when printing
> > straight to the canvas with " p.drawImage
> > ('/root/journal/gazette/paper1.png', 0, 0, width=None, height=None,
> > mask=None)" but I need to use Platypus.
> >
>
> [...]
> > 671. raise LayoutError(ident)
> >
> > LayoutError at /gazette/test/
> > Flowable <Image at -0x4950c374 frame=normal
> > filename=/root/journal/gazette/paper1.png> too large on page 2
> >
> > What am I doing wrong?
>
> you can embed this into a 'KeepInFrame' object
> for example
>
> from reportlab.platypus.flowables import KeepInFrame
> from reportlab.platuyps import Image
>
> [ ...some code... ]
>
> image = Image(<... whatever ...>)
> story.append(KeepInFrame(MAXWIDTH, MAXHEIGHT, [image])
>
> this will scale you image in such a way that it's not larger than
> MAXWIDTH, MAXHEIGHT.
>
> Hope that helps
>
> Stephan
>
>
> >
> > Thanks!
> > Erik
> > |
> >
> >
> >
> ------------------------------------------------------------------------
>
> >
> > _______________________________________________
> > reportlab-users mailing list
> > reportlab-users at reportlab.com <mailto:reportlab-users at reportlab.com>
> > http://two.pairlist.net/mailman/listinfo/reportlab-users
>
> _______________________________________________
> reportlab-users mailing list
> reportlab-users at reportlab.com <mailto:reportlab-users at reportlab.com>
> http://two.pairlist.net/mailman/listinfo/reportlab-users
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> 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