我想使用Cairo生成一个多页PDF文档,其中每个页面共享一个公共模板。是否可以使用Cairo的PDF Form XObjects,以便每个页面共享相同的模板,只将自定义添加到页面?
我尝试过使用Context.set_source_surface
,但它似乎在绘画前光栅化表面:
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()
答案 0 :(得分:1)
使用记录表面而不是PDF表面作为模板。此外,不需要template_ctx.fill()行。