[reportlab-users] determine the color of a pixel

pier carteri pier.carteri at gmail.com
Fri Oct 27 06:16:16 EDT 2006


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
On 10/26/06, Tim Roberts <timr at probo.com> wrote:
> pier carteri wrote:
>
> >
> > is it possible to know the color of a particular region of the canvas?
> > somethings like
> > canvas.getColorAtPosition(pos_x, pos_y)
>
>
> No.  The canvas does not maintain a bitmap with all of the stuff you've
> drawn.  A PDF file isn't actually turned into a bitmap until it gets
> into an Acrobat Reader.
>
>
> > If no, is it possible to know which object (line, text, rectangle ...)
> > is present in a particular position on the canvas?
> > somethings like
> > canvas.getObjectsAtPosition(pos_x, pos_y)
>
>
> No.  The canvas doesn't remember all of that.  It converts each call
> into a Postscript command string, and adds that string to the current
> Postscript program.  It's just text characters.
>
> What are you actually trying to do?  You can certain keep a list of
> objects yourself.
>
> --
> Tim Roberts, timr at probo.com
> Providenza & Boekelheide, Inc.
>
> _______________________________________________
> reportlab-users mailing list
> reportlab-users at reportlab.com
> http://two.pairlist.net/mailman/listinfo/reportlab-users
>


More information about the reportlab-users mailing list