[reportlab-users] Position Paragraph or how to get current position

1,813 views
Skip to first unread message

Mike Driscoll

unread,
Oct 16, 2013, 5:39:43 PM10/16/13
to reportlab-users
Hi,

I am attempting to add a table and then a Paragraph to my document list that I plan to build. The table looks like it's in the right place, but the Paragraph is indented about an inch. Is there a way to position the Paragraph object along it's horizontal axis?

Here's a slightly different question. If I wanted to switch to purely canvas-based drawing, is there a way to tell where a table ends so I wouldn't draw over it? For example, if I drew a table using its drawOn() method, is there a way to tell where the table's last line of data was drawn so I could draw underneath it?

Thanks,

-------------------
Mike Driscoll

Blog:   http://blog.pythonlibrary.org

Andy Robinson

unread,
Oct 18, 2013, 3:27:33 PM10/18/13
to reportlab-users
Mike, on the table: you can draw any flowable in canvas mode if you first call
object.wrap(availWidth, availHeight), which will return the width
and height within that space that it actually wants to use.
Practically, width was never used and is always the width of the
frame, but height tells you where your table will end.


This height will be to the bottom of the table. We define the edges
as a zero-width line at the midpoint of the bottom border. However,
by default all table cells have 3 points of padding between the
content and edges (overrideable by you) on the inside; there is no
padding around the inside. So to put a paragraph straight after,
you'll want to set its baseline a bit lower.

This is going from memory as I don't have a development environment to
hand. Hope it helps...
> _______________________________________________
> reportlab-users mailing list
> reportl...@lists2.reportlab.com
> http://two.pairlist.net/mailman/listinfo/reportlab-users
>



--
Andy Robinson
Managing Director
ReportLab Europe Ltd.
Thornton House, Thornton Road, Wimbledon, London SW19 4NG, UK
Tel +44-20-8405-6420
_______________________________________________
reportlab-users mailing list
reportl...@lists2.reportlab.com
http://two.pairlist.net/mailman/listinfo/reportlab-users

Mike Driscoll

unread,
Oct 21, 2013, 9:59:31 AM10/21/13
to reportlab-users
Hi Andy,


On Fri, Oct 18, 2013 at 2:27 PM, Andy Robinson <an...@reportlab.com> wrote:
Mike, on the table:  you can draw any flowable in canvas mode if you first call
   object.wrap(availWidth, availHeight), which will return the width
and height within that space that it actually wants to use.
Practically, width was never used and is always the width of the
frame, but height tells you where your table will end.


This height will be to the bottom of the table.  We define the edges
as a zero-width line at the midpoint of the bottom border.  However,
by default all table cells have 3 points of padding between the
content and edges (overrideable by you) on the inside; there is no
padding around the inside.  So to put a paragraph straight after,
you'll want to set its baseline a bit lower.

This is going from memory as I don't have a development environment to
hand.  Hope it helps...

I think I got the padding removed using the table's style options, specifically BOTTOMPADDING and TOPPADDING. But I'm still not sure how I can control the indent of the following flowables. I really want to move the Paragraph object that follows the table to the left about half an inch.

- Mike

Robin Becker

unread,
Oct 21, 2013, 12:34:20 PM10/21/13
to reportlab-users
On 21/10/2013 14:59, Mike Driscoll wrote:
> Hi Andy,
>
>
..........
>
>
> I think I got the padding removed using the table's style options,
> specifically BOTTOMPADDING and TOPPADDING. But I'm still not sure how I can
> control the indent of the following flowables. I really want to move the
> Paragraph object that follows the table to the left about half an inch.
>
> - Mike
........

Mike,

our paragraphs try to use all the horizontal space available to them. That means
the container doesn't control where the paragraph aligns itself. That's a
problem if you want ragged right and aligned right as I don't think we can do that.


For traditional left/right center etc (and ignoring any cell padding issues) you
need to set the paragraph's style.alignment to one of

TA_LEFT, TA_RIGHT, TA_CENTER, TA_JUSTIFY (found in from reportlab.lib.enums)

to get the desired behaviour. The default is TA_LEFT.
--
Robin Becker

Mike Driscoll

unread,
Oct 21, 2013, 1:29:48 PM10/21/13
to reportlab-users
Hi Robin,


On Mon, Oct 21, 2013 at 11:34 AM, Robin Becker <ro...@reportlab.com> wrote:
........

Mike,

our paragraphs try to use all the horizontal space available to them. That means the container doesn't control where the paragraph aligns itself. That's a problem if you want ragged right and aligned right as I don't think we can do that.


For traditional left/right center etc (and ignoring any cell padding issues) you need to set the paragraph's style.alignment to one of

TA_LEFT, TA_RIGHT, TA_CENTER, TA_JUSTIFY (found in from reportlab.lib.enums)

to get the desired behaviour. The default is TA_LEFT.
--
Robin Becker

__


I actually figured out a way to accomplish what I wanted. I just created a custom ParagraphStyle and set the leftIndent parameter to -50, which made it line up where I needed it. Thanks for your advice though.

Andy Robinson

unread,
Oct 22, 2013, 5:23:59 AM10/22/13
to reportlab-users
Mike. I'm glad to hear that worked. I had never actually tried a
negative indent in a paragraph but in general, "drawing outside the
box" is allowed and very helpful in our framework...

Mike Driscoll

unread,
Oct 22, 2013, 9:33:05 AM10/22/13
to reportlab-users
Andy,

I had never tried it either, but I figured it was worth a try.

Thanks for the really flexible framework.

Mike

--
Reply all
Reply to author
Forward
0 new messages