[reportlab-users] determine the color of a pixel

Robin Becker robin at reportlab.com
Fri Oct 27 06:30:27 EDT 2006

pier carteri wrote:
> Yes, sorry, my questions were a bit confused.
> I will explain my problem in a bit more detail.
> I' ve a program divided in two parts; the first one composes box on
> the canvas, the second one draws string. The second part ignores what
> has been drawed on canvas.
> A bit of code:
> from reportlab.pdfgen import canvas
> c = canvas.Canvas("test.pdf")
> #first part
> c.lines([(20,20,60,20),
>           (20,20,20,40),
>           (60,20,60,40),
>           (20,40,60,40),
>         ])
> #second part
> c.drawString(25,25, "Test")
> c.save()
> What I would like to obtain is that if the string I'm drawing is
> inside one of the box, than the background of the box will change. For
> this purpouse I need to find what is actually drawed on the canvas. Of
> course I can store informations about all the object I've previously
> written on the canvas, than pass these informations to the second part
> of my program but I'm not sure if it's the best solution... Any dea?
> Thank you!
> Pier
as explained earlier it's pretty hard for reportlab functions to determine what 
will actually show up on the canvas. It seems fairly obvious that the boxes you 
are drawing and the presence/absence of text are connected so wouldn't the best 
thing be to combine them at the point where your text is drawn.

It doesn't follow that you have to draw the whole of the box at that point, but 
provided your coordinates are right the presence/absence of letters (or text) 
could be used to draw an additional coloured rectangle or change the fill of 
what you draw.
Robin Becker

More information about the reportlab-users mailing list