生成&在 Python 中合并 PDF 文件
我想用Python自动生成预订确认PDF文件。大多数内容将是静态的(即徽标、预订条款、电话号码),以及一些动态内容(日期、成本等)。
从用户方面来看,最简单的方法是从包含静态内容的 PDF 文件开始,然后使用 python 添加动态部分。这是一个简单的过程吗?
经过一些搜索,我似乎可以使用reportlab来创建内容,使用pyPdf将PDF合并在一起。这是最好的方法吗?还是有一种我还没有遇到过的非常时髦的方式?
谢谢!
I want to automatically generate booking confirmation PDF files in Python. Most of the content will be static (i.e. logos, booking terms, phone numbers), with a few dynamic bits (dates, costs, etc).
From the user side, the simplest way to do this would be to start with a PDF file with the static content, and then using python to just add the dynamic parts. Is this a simple process?
From doing a bit of search, it seems that I can use reportlab for creating content and pyPdf for merging PDF's together. Is this the best approach? Or is there a really funky way that I haven't come across yet?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不幸的是没有。有几种工具可以很好地从头开始生成 PDF(最常见的是 Python,ReportLab) ,但它们通常不会加载现有的 PDF。您必须为任何样板文本、线条、块、形状和图像生成代码,而不是由用户自由编辑。
另一方面,pyPdf 可以加载 PDF、整理页面并提取一些信息,但可以并没有真正添加新内容。您可以将页面“合并”为一个页面,但您仍然必须首先在 ReportLab 中将额外的信息叠加层创建为页面。
Unfortunately no. There are several tools that are good at producing PDFs from scratch (most commonly for Python, ReportLab), but they don't generally load existing PDFs. You would have to include generating code for any boilerplate text, lines, blocks, shapes and images, rather than this being freely editable by the user.
On the other side there's pyPdf which can load PDFs, collate the pages, and extract some of the information, but can't really add new content. You can ‘merge’ pages into one, but you'd still have to create the extra information overlay as a page in ReportLab first.
查看 docutils 和 reSTructuredText。您可以在 reST 中快速写出 PDF 文档,然后使用 rst2pdf.py 编译 PDF
我已经使用过这个,它创建了非常漂亮的文档,并且标记是可扩展的!稍后您可以使用相同的代码并将其运行到 rst2html 中以创建一个网站!
看看这里:
祝你好运
Look into docutils and reSTructuredText. You could quickly write out your PDF document in reST and then compile the PDF using rst2pdf.py
I've used this, it creates very beautiful documents and the markup is extensible! Later you could take the same code and run it into rst2html to create a website out if it!
Take a look here:
Good luck
您可以通过 TeX、OpenOffice 或其他任何给您最舒适的装订方式生成文档,然后使用 pdf 打印机打印该文档。
这使您不必弄清楚在哪里精确放置字段,也不必弄清楚如果您的内容溢出为其分配的空间该怎么办。
You could generate a document through, for example, TeX, or OpenOffice, or whatever gives you the most comfortable bindings and then print the document with a pdf printer.
This allows you not to have to figure out where to put fields precisely or figure out what to do if your content overflows the space allocated for it.