[reportlab-users] Fwd: text of paragraph sits at bottom of area.
Kerri Reno
kreno at yumaed.org
Thu Apr 9 12:12:21 EDT 2009
Thank you Tim and Robin for your help. That's exactly what I needed. I
didn't know that wrapOn returned the size of the paragraph, so I was worried
that I'd have to somehow calculate it myself, and I didn't have a clue how
to do that.
Thanks again!
Kerri
On Tue, Apr 7, 2009 at 9:28 AM, Kerri Reno <kreno at yumaed.org> wrote:
> Thanks for your suggestions! I will try them out, and let you know.
>
> Kerri
>
>
> On Tue, Apr 7, 2009 at 3:52 AM, Robin Becker <robin at reportlab.com> wrote:
>
>> Kerri Reno wrote:
>> .........
>>
>>
>>> I'm creating a pay stub with reportlab, that has to fit on one page. I
>>> started with Jeff Bauer's hcfa1500.py from the reportlab web site -
>>> THANKS
>>> JEFF! I was able to modify it to fit my needs, even including a couple
>>> of
>>> paragraphs. My problem is that the paragraphs print in the bottom of the
>>> allowed area.
>>>
>>> I'm using
>>>
>>> stylesheet = getSampleStyleSheet()
>>> style = stylesheet['Normal']
>>> style.fontName=self.text_font
>>> style.fontSize = self.text_size
>>> style.leading = int(self.text_size * 1.2)
>>> c = self.canvas
>>>
>>> # x, y = bottom left corner of area
>>> # width and height are the maximum area I want the
>>> # paragraph to use up
>>> p = Paragraph(v,style)
>>> f = KeepInFrame(width,height,[p],mode='shrink')
>>> f.wrapOn(c,width,height)
>>> f.drawOn(c,x,y)
>>>
>>> This works great, except if the text of the paragraph doesn't take up all
>>> the space, then it prints in the bottom portion of the area.
>>>
>>> I've searched the documentation and the web for an answer, and I just
>>> can't
>>> find it. I'd appreciate any help you can give me.
>>>
>>> Thanks in Advance!
>>> Kerri
>>>
>>> ........
>>
>> first off the normal way of drawing paragraphs is with the platypus
>> doctemplate frame work. But if you wish to do this directly into a canvas
>> then it's wise to know the api that's used.
>>
>> First off wrap/wrapOn return the width and height that is used by the
>> flowable;
>>
>> eg
>> # NB w, h don't have to be equal to width and height
>> w,h = f.wrapOn(c,width,height)
>>
>> then the x and y for the drawOn correspond to the bottom left of the
>> flowable. Assuming you wish to draw from the top down you need to subtract
>> the height from the top left y.
>>
>>
>>
>> try this script to get some idea of where things are
>>
>> from reportlab.pdfgen.canvas import Canvas
>> from reportlab.lib.styles import getSampleStyleSheet
>> from reportlab.platypus.paragraph import Paragraph
>> from reportlab.platypus.flowables import KeepInFrame
>> stylesheet = getSampleStyleSheet()
>> style = stylesheet['Normal']
>> style.fontName = 'Helvetica'
>> style.fontSize = 10
>> style.leading = int(style.fontSize * 1.2)
>> c = Canvas('simple.pdf')
>>
>> width=72 #1in x 1in width for our para
>> height=72
>>
>> #define top left
>> tlx = 72 #one inch in from left
>> tly = c._pagesize[1] - 72 #one inch down from top
>>
>> #show our area
>> c.setLineWidth = 1
>> c.setStrokeColor((1,0,0)) #red
>> c.rect(tlx,tly,width,-height,stroke=1,fill=0)
>>
>> p = Paragraph('This is a silly paragraph that\'s used to make up the
>> numbers and show the world where things go.',style)
>> f = KeepInFrame(width,height,[p],mode='shrink')
>> w,h=f.wrapOn(c,width,height)
>> f.drawOn(c,tlx,tly-height)
>> c.showPage()
>> c.save()
>> --
>> Robin Becker
>>
>> _______________________________________________
>> reportlab-users mailing list
>> reportlab-users at reportlab.com
>> http://two.pairlist.net/mailman/listinfo/reportlab-users
>>
>
>
>
> --
> Yuma Educational Computer Consortium
> Compass Development Team
> Kerri Reno
> kreno at yumaed.org (928) 502-4240
> .·:*¨¨*:·. .·:*¨¨*:·. .·:*¨¨*:·.
>
--
Yuma Educational Computer Consortium
Compass Development Team
Kerri Reno
kreno at yumaed.org (928) 502-4240
.·:*¨¨*:·. .·:*¨¨*:·. .·:*¨¨*:·.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://two.pairlist.net/pipermail/reportlab-users/attachments/20090409/0ce1a9f2/attachment.html>
More information about the reportlab-users
mailing list