【问题标题】:Use PDF Form XObjects with Cairo's PDF surface?将 PDF 表单 XObjects 与 Cairo 的 PDF 表面一起使用?
【发布时间】:2014-01-18 08:51:58
【问题描述】:

我想使用 Cairo 生成一个多页 PDF 文档,其中每个页面共享一个通用模板。是否可以使用来自 Cairo 的 PDF 表单 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()

【问题讨论】:

  • 经过更多寻找,我还没有找到解决方案。目前,我的用例看起来最好的选择是使用 Cairo 渲染 PDF,然后使用 PyPDF2 将它们合并在一起。

标签: pdf cairo


【解决方案1】:

为您的模板使用记录表面而不是 PDF 表面。此外,不需要 template_ctx.fill() 行。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多