[reportlab-users] How to use graphics Drawing objects with pdfgen Canvas

tim graber tgraber_us at yahoo.com
Mon Nov 28 12:28:57 EST 2005


In the graphics guide, I found this paragraph on using
a drawing object directly with Platypus or
pdfgen/canvas.  I have been trying to figure out how
to incorporate the graphics Drawing object directly
onto a pdfgen Canvas object.  Does anyone have any
experience with this?  Thanks.

"The PDF renderer has special "privileges" - a Drawing
object is also a Flowable and, hence, can be placed
directly in the story of any Platypus document, or
drawn directly on a Canvas with one line of code. In
addition, the PDF renderer has a utility function to
make a one-page PDF document quickly."

from reportlab.pdfgen import canvas
from reportlab.graphics.shapes import *
from reportlab.lib import colors
from reportlab.lib.units import inch

c = canvas.Canvas("hello.pdf")
c.translate(1*inch,1*inch)
d = Drawing(400, 200)
#d.add(Rect(50, 50, 300, 100,
fillColor=colors.yellow)) d.add(String(150,100, 'Hello
World', fontSize=18)) c.drawImage(d, inch, inch, 130,
48)




More information about the reportlab-users mailing list