[reportlab-users] Getting the number of lines in a frame

Saketh Bhamidipati saketh.bhamidipati at gmail.com
Mon Aug 21 20:50:00 EDT 2006

On 8/21/06, Robin Becker <robin at reportlab.com> wrote:
> Saketh Bhamidipati wrote:
> .......
> >>
> > Is there any way that I can get the text which is written to the frame
> with
> > all breaks returned as if they were newlines? That would be enough to
> solve
> > my problem.
> >
> > Let us say that a frame breaks a line of text. Is there some way that I
> can
> > get the frame's text with the line break returned as a newline? Then I
> > could
> > count the number of newlines before breaking, count the number of
> newlines
> > after breaking, and the difference is the number of lines.
> the paragraph has a wrap method which effectively breaks the lines using a
> specified width and height. So
> P.wrap(availWidth,availheight)
> returns the required width and height determined from the way the
> paragraph
> splits. Unfortunately for performance reasons the broken lines are stored
> in a
> fairly complex way in P.blPara.lines. So the height of the paragraph is
> len(P.blPara.lines)*P.style.leading.
> --
> Robin Becker
> _______________________________________________
> reportlab-users mailing list
> reportlab-users at reportlab.com
> http://two.pairlist.net/mailman/listinfo/reportlab-users

I expected that this would happen, and it did:

Traceback (most recent call last):
  File "C:\Python24\Projects\PDF\hanuman.py", line 114, in -toplevel-
    test.appendText("Test 2")
  File "C:\Python24\Projects\PDF\hanuman.py", line 95, in appendText
    self.hloc += len(p.blPara.lines)*p.style.leading
AttributeError: Paragraph instance has no attribute 'blPara'

Here's my important code:
    def appendText(self, text):
        p = Paragraph(bullet(text), self.style)
        if self.textcalled:
            # It used to be 1, not len(p.blPara...
            self.hloc += len(p.blPara.lines)*p.style.leading
        self.textcalled = True

Thanks for helping me.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://two.pairlist.net/pipermail/reportlab-users/attachments/20060821/20e40484/attachment.html

More information about the reportlab-users mailing list