如何在Python中将图像添加到PDF文件? [英] How to add image to PDF file in Python?

查看:1268
本文介绍了如何在Python中将图像添加到PDF文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PDF文档,但是我必须在上面放上自己的图像.这是正式文档,我必须在整个页面上应用带有示例"文字的图片.

I have a PDF document but I must put my own image on it. It's an official document and I must apply an image with the text "example" to the whole page.

有什么办法可以解决python中的这个问题?

Is there any way to solve this problem in python?

(文档中的文本为曲线)

(text in the document is curves)

推荐答案

查看 PyPDF .您可能会使用类似以下代码的内容来套用叠加层:

Look into PyPDF. You might use something like the following code to apply an overlay:

page = PdfFileReader(file("document.pdf", "rb")).getPage(0)
overlay = PdfFileReader(file("overlay.pdf", "rb")).getPage(0)
page.mergePage(overlay)

将所需的任何叠加层(包括示例")放入overlay.pdf. 就我个人而言,我更喜欢PDFTK,尽管它不是严格的Python,但可以使用os.system(command)从脚本中调用.

Put any overlay you want, including "Example", into overlay.pdf. Personally, I prefer PDFTK, which, while not strictly Python, can be invoked from a script with os.system(command).

这篇关于如何在Python中将图像添加到PDF文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆