I
I
Ilya Snopkov2021-09-14 15:01:07
Python
Ilya Snopkov, 2021-09-14 15:01:07

Automation of layout in printing, help)?

Good day, I’m turning to professionals) I recently began to “study” the field of programming and immediately the idea was born in the following way, how to set up uploading a template to PDF format with a certain size, so that the template takes the necessary text from excel, and a photo from Explorer, can you advise some any lessons on this topic?
just in case, I attach a photo of what I want, I hope you understand me ...61408d9e34b64070949223.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
ScriptKiddo, 2021-09-14
@ScriptKiddo

Creating PDF files
https://python-scripts.com/create-pdf-pyfpdf
Reading Excel files
https://openpyxl.readthedocs.io/en/stable/
Example of reading a file
https://openpyxl.readthedocs.io/en/ stable/usage.ht...

S
Sergey Pankov, 2021-09-14
@trapwalker

I solved similar tasks like this:
- In Inkscape, I prepared the layout of the document in svg format. Inside the SVG is a plain text XML file.
- Then a template was built on its basis, we used the standard django template engine, but you can take a third-party one, for example, Jinja or any other, thousands of them. Our document structure was much more complicated than yours, and I used multi-level templates for different fragments of the document. Yes, WISIWIG did not succeed in editing templates, but such a task was not critical. In your case, the template turns out to be trivial and you can even do substitution at the row level, only the escaping needs to be done carefully.
This was already done ten years ago. Maybe there are better tools out there now. Didn't follow the news in this direction.
- Next, the template is rendered filled with data from the context, and the final SVG document is processed by the headless Inkscape editor instance, which was running on a separate virtual machine, and later launched in a docker container. This is actually running Inkscape -A document.svg document.pdf which converts the document to a pdf file.
As a result, the resulting pdfs are optionally assembled into one to make a multi-page document and it was more convenient to print it. I don’t remember which library was used for this, but the task is common and simple, you will find it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question