[cairo] Putting PNGs into PDFs using pycairo?

Steve Schwarz steve at agilitynerd.com
Mon Oct 18 06:50:05 PDT 2010


Hi,
I'm pretty new to pycairo and I'd like to insert PNG images into PDFs and it
looks like I'm not doing so correctly:

import cairo

def pngInPDF():
    pdf_file = open("test.pdf", 'wb')
    surface = cairo.PDFSurface(pdf_file, 595, 841)
    context = cairo.Context(surface)
    png_surface = cairo.ImageSurface.create_from_png('test.png')
    context.set_source(png_surface)

I get a traceback on the set_source() call:
     context.set_source(png_surface)
TypeError: Context.set_source() argument 1 must be cairo.Pattern, not
cairo.ImageSurface

I'd appreciate any pointers on the correct way of doing this.

Best Regards,
Steve
http://tech.agilitynerd.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cairographics.org/archives/cairo/attachments/20101018/4e55fbb1/attachment.htm>


More information about the cairo mailing list