用Python在现有PDF文档中添加文本 [英] Add text to existing PDF document in Python

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

问题描述

我正在尝试将pdf转换为与我的pdf(A4页面)相同的大小。

I'm trying to convert a pdf to the same size as my pdf which is an A4 page.

convert my_pdf.pdf -density 300x300 -page A4 my_png.png

生成的png文件,但是,是595px×842px,应该是72 dpi的分辨率。
我正在考虑使用PIL在一些pdf字段上写一些文本并将其转换回PDF。但目前图像出错了。

The resulting png file, however, is 595px × 842px which should be the resolution at 72 dpi. I was thinking of using PIL to write some text on some of the pdf fields and convert it back to PDF. But currently the image is coming out wrong.

编辑:我从错误的角度接近问题。正确的方法根本不包括imagemagick。

I was approaching the problem from the wrong angle. The correct approach didn't include imagemagick at all.

推荐答案

你应该看看使用Python向现有PDF添加文本以及 Python as PDF编辑和处理框架。这些将指向正确的方向。

You should look at Add text to Existing PDF using Python and also Python as PDF Editing and Processing Framework. These will point you in the right direction.

如果您执行了问题中的建议,当您导出回 .pdf ,它实际上只是一个嵌入在 .pdf 中的图像文件,它不是文本。

If you do what you've proposed in the question, when you export back to .pdf, it will really just be an image file embedded in a .pdf, it won't be text.

这篇关于用Python在现有PDF文档中添加文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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