#!/usr/local/bin/python import cairo f = file('test-pdf.pdf', 'wb') ctx = cairo.Context() ctx.set_target_pdf(f, 4, 3, 72, 72) ctx.set_rgb_color(.5, .5, .5) ctx.rectangle(0, 0, 3, 2) ctx.stroke() ctx.show_page()