[reportlab-users] Text Background

Paul Barrass paul.barrass at safeonlinebilling.com
Thu Jun 11 12:48:46 EDT 2009


Joel Wickard wrote:

> I have a line I'm drawing with canvas.line, that I want to place a

> text label in the middle of. If I use a text object, then the line

> and the text sort of co-mingle, I'm looking for the text to sort of

> clip the line out and create a white background / slight left & right

> padding.

>

> Anyone want to give me a starting direction on this? In the past

> using something like illustrator if I was doing this by hand I would

> have just created a white block behind the text as a separate object,

> I'm just checking to see if we have a different options with

> reportlab.

>

If you're trying to achieve what I think you are - you could use a white
(or whatever background colour you're using) stroke and black (or
whatever...) fill - this would (maybe, I've not tried it) create a white
border around the characters which would overwrite the line, forming
some padding. You'll need .setStrokeColor(colors.white) and
.setTextRenderMode(3) [for stroke+fill] on the textObject.

Alternatively, you could draw a white solid block 'between' the line and
the text - there are method for working out the width of a string so you
can set the box to the appropriate size.

Paul Barrass.


More information about the reportlab-users mailing list