mimischi / django-clock

A tool for student assistans at the Goethe University to keep track of their work time.
MIT License
3 stars 2 forks source link

Change PDF renderer #447

Open mimischi opened 6 years ago

mimischi commented 6 years ago

We are currently using ReportLab to render the exported PDFs. While it is a great library, the whole PDF layout is defined inside Python code and adaptation to new designs is tedious.

Instead of generating the PDF from scratch, we should use a HTML template (or something similar) to define the layout. Then we can use some external library to convert that to PDF.

Here are a few possible converters that I've stumbled upon:

I've only tested wkhtmltopdf and it converts HTML templates made with Bootstrap 4 almost without problems! There's also an Alpine Linux package being developed, so we should be able to install it as a dependency in our Dockerfile.

Here is a first layout using Bootstrap 4. It's not a perfect replica of the original template, but I think it's pretty good. Also I've attached a PDF that was converted with wkhtmltopdf. The only thing that does not seem to work is the table-striped class from Boostrap, thus we do not get alternating row backgrounds.

What do you think about the template @sheepyhollow?

chgad commented 6 years ago

Agreed. The Exportlayout is, as layouts nearly allways are, basically static. Html templates are quite common for this but one could also consider Latex templates with the corresponding Sevice PdfCreator (if there exists a API we can acces).

mimischi commented 6 years ago

So far I've tried wkhtmltopdf and this worked with the example HTML+PDF linked above. It's a simple package we can install inside the apps Docker container and just call it from within our code. I don't see, why we should use a different service. Additionally, we would need to re-create the Stundenzettel in TeX, whereas the work in HTML is already done.

sheepyhollow commented 6 years ago

I think I commented on the template in November already (personally, I guess). Looks good to me - just the page margins should be adjusted.

I agree that LaTeX templates are attractive in their way, but let's stick with what works and keep it simple.

mimischi commented 6 years ago

This is the latest version that I managed to accomplish recently (Source here).

The PDF was generated with the following command:

wkhtmltopdf --margin-bottom 10 --margin-top 10 --margin-left 20 --margin-right 20 index.html clock_arbeitszeitblatt_201805.pdf
sheepyhollow commented 6 years ago

much better.