Code snippets are bits of re-usable code submitted by the ReportLab community. We don't promise that they are accurate, up-to-date or correct - use them at your own risk!
We'd love it if you could participate by submitting your own snippets and sharing your experience with others by commenting. You will need to create a user account by filling out our very simple form.
View all snippets
Canvas text on an image
This simple script illustrates drawing an image on a canvas and overdrawing with text.
from reportlab.lib.utils import ImageReader
from reportlab.pdfgen.canvas import Canvas
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.pdfbase.pdfmetrics import registerFont
from reportlab.lib.pagesizes import A4
canv = Canvas('text-on-image.pdf',pagesize=A4)
img = ImageReader('pythonpowered.gif')
#now begin the work
x = 113
y = 217
w = 103
h = 119
canv.setFillColor((1,0,0)) #change the text color