2014-01-18 60 views
1

我想用Cairo生成一個多頁PDF文檔,其中每個頁面共享一個通用模板。是否可以使用Cairo的PDF Form XObjects,因此每個頁面將共享相同的模板,只將定製添加到頁面中?使用PDF格式的XObjects與開羅的PDF表面?

我使用Context.set_source_surface嘗試過,但似乎塗裝前表面光柵化:

example using 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

經過更多的尋找,我還沒有找到一個解決方案。目前,我的使用案例看起來最好的選擇是使用Cairo來渲染PDF,然後PyPDF2將它們合併在一起。 –

回答

0

使用記錄面,而不是爲你的模板PDF表面。另外,template_ctx.fill()行不是必需的。