title: Use PDF Form XObjects with Cairo's PDF surface?
body: <p>I'd like to use Cairo to generate a multi-page PDF document where each page shares a common template. Is it possible to use PDF Form XObjects from Cairo so each page will share the same template, only adding the customizations to the page?</p>
  
  <p>I've tried using <a href="http://cairographics.org/documentation/pycairo/2/reference/context.html#cairo.Context.set_source_surface" rel="nofollow noreferrer"><code>Context.set_source_surface</code></a>, but it seems to rasterize the surface before painting:</p>
  
  <p><img src="https://i.stack.imgur.com/BdiVB.png" alt="example using set_source_surface"></p>
  
  <pre><code>import cairo
  
  template_sfc = cairo.PDFSurface("/tmp/template.pdf", 600, 600)
  template_ctx = cairo.Context(template_sfc)
  template_ctx.move_to(20, 20)
  template_ctx.set_source_rgb(0, 0, 0)
  template_ctx.show_text("HELLO")
  template_ctx.fill()
  
  sfc = cairo.PDFSurface("/tmp/actual.pdf", 612, 792)
  ctx = cairo.Context(sfc)
  ctx.set_source_surface(template_sfc)
  ctx.paint()
  sfc.finish()
  </code></pre>