this should do the trick. First you need to convert the image to png, this is apparently the only format with which you can create surfaces. here is what makes a good piece of code below. I recommend that you look at this question , which helped me in creating the code below.
import Image, StringIO from cairo import PDFSurface, Context, ImageSurface pdf = PDFSurface("out.pdf", 1000, 1000) cr = Context(pdf) im = Image.open("/home/seif/Pictures/prw.jpg") buffer = StringIO.StringIO() im.save(buffer, format="PNG") buffer.seek(0) cr.save() cr.set_source_surface(ImageSurface.create_from_png(buffer)) cr.paint()
source share