def draw_page(operation, context, page_nr):
cr = context.get_cairo_context()
# Draw a red rectangle, as wide as the paper (inside the margins)
cr.set_source_rgb(1.0, 0, 0)
cr.rectangle(0, 0, context.get_width(), 50)
cr.fill()
# Draw some lines
cr.move_to(20, 10)
cr.line_to(40, 20)
cr.arc(60, 60, 20, 0, M_PI)
cr.line_to(80, 20)
cr.set_source_rgb(0, 0, 0)
cr.set_line_width(5)
cr.set_line_cap(cairo.LINE_CAP_ROUND)
cr.set_line_join(cairo.LINE_JOIN_ROUND)
cr.stroke()
# Draw some text
layout = context.create_layout()
layout.set_text("Hello World! Printing is easy")
desc = pango.FontDescription("sans 28")
layout.set_font_description(desc)
cr.move_to(30, 20)
layout.layout_path()
# Font Outline
cr.set_source_rgb(0.93, 1.0, 0.47)
cr.set_line_width(0.5)
cr.stroke_preserve()
# Font Fill
cr.set_source_rgb(0, 0.0, 1.0)
cr.fill()