M
M
Maxim Zubenko2019-06-26 00:56:07
Django
Maxim Zubenko, 2019-06-26 00:56:07

How to make payment slips in pdf in python?

Good time everyone.
I do projects on Django and sometimes customers set tasks that, using the methods that I already know, are extremely difficult to do.
How do I work in pdf now and what do I do.

  • From the product catalog, a price is made in pdf
  • Order forms are made with a list of products, their quantity and amount at the end

To create the above, simple table-based HTML templates were made and css styles for printing were made for a very long time and gemorno. A million test files have been generated and hundreds of paper versions have been printed. To generate the PDF, I use the weasyprint battery, which I feed the rendered HTML template and CSS for printing. As a result, it looks tolerable, and the customer is satisfied with the result and everyone is happy.
But now the task has come that you need to take a whole group of different forms, fill them with data, and at the output give the same PDF. It is impossible to follow the path described above, because. forms must be the same as provided by the customer.
Drawing in HTML is hard for me and it will take an extremely long time. And it’s hard to write css print for all this. Again, if something suddenly changes, or some other form is brought, then it’s crazy to redraw everything and test it again.
By the way, the forms were provided in the usual Word (docx) format and they can be saved from the Word in many different formats.
Has anyone already done this exact task? To fill a specific form with data and output it to PDF?
As I see it.
  1. In the form (in the Word) I enter some "lighthouses".
  2. I save forms in some tricky format, the file of which ...
  3. I open it with a python and, having found the left beacons, I replace them with the necessary data
  4. I save a new, freshly laid out letterhead file in the same tricky format
  5. Using something from a file in a tricky format, I generate a ready-made PDF in which the form looks exactly like in the original .

Accordingly, the questions are:
In what format can it be saved so that this file can be opened to replace data and at the same time the reference formatting of the form is saved in the same file?
What extension can be used to convert all this to PDF?
ps Please do not offer batteries for python2.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2019-06-26
@Survtur

LibreOffice has a headless mode. It can convert to PDF.
Moreover, it can be controlled from Python scripts. And this means that you can edit not the source code in XML, but replace the text of "anchors" in the program itself.

M
milssky, 2019-06-26
@milssky

Was LaTeX considered an option?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question