简体   繁体   中英

Generating & Merging PDF Files in Python

I want to automatically generate booking confirmation PDF files in Python. Most of the content will be static (ie 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!

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?

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.

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM