Create and merge PDF files in Python

I want to automatically create booking confirmation files for PDF files in Python. Most of the content will be static (e.g. logos, booking conditions, phone numbers) with several dynamic bits (dates, costs, etc.).

From the user's point of view, the easiest way would be to start with a PDF file with static content, and then with python just add dynamic parts. Is this a simple process?

By doing a bit of searching, it seems that I can use reportlab to create content and pyPdf to merge PDF together. Is this a better approach? Or is there a really funky way that I haven't come across yet?

Thanks!

+4
source share
3 answers

From the user's point of view, the easiest way would be to start with a PDF file with static content, and then with python just add dynamic parts. Is this a simple process?

Unfortunately not. There are several tools that are good at creating PDF files from scratch (most often for Python, ReportLab ), but usually they do not load existing PDF files. You will need to enable the generation code for any text text, lines, blocks, shapes and images, and not for free editing by the user.

On the other hand, pyPdf , which can load PDF files, sort pages and extract some of the information, but cannot really add new content. You can "merge pages into one, but you still have to create additional overlay information as a page in ReportLab in the first place.

+8
source

Look at the docutils and rebuild the Text. You can quickly write your PDF document in the registry and then compile the PDF using rst2pdf.py

I used this, it creates very beautiful documents, and the markup is extensible! Later you can take the same code and run it in rst2html to create a site if it is!

Take a look here:

Good luck.

+2
source

You can generate a document using, for example, TeX or OpenOffice, or something that gives you the most convenient bindings, and then print the document using a pdf printer.

This allows you to not determine where to place the fields exactly or figure out what to do if your content overflows the space allocated for it.

+1
source

Source: https://habr.com/ru/post/1301289/


All Articles