Last Updated: February 25, 2016
·
1.439K
· strycore

Generating Reportlab PDFs with live preview

When writing some code that generates a PDF, it can be quite annoying to write some code, then generate the PDF to see the results. Here's a tip to see the modifications you make to your code in near realtime.

First, write a unit test that will generate your file, it's important to have something that is not tightly coupled with your web views. If you're using Django, add some fixtures to the TestCase if you need them.

When your TestCase is working, launch it with this command (assuming you're using Django):

watch ./manage.py test myapp.GeneratePdf

This will run the tests over and over, and will tell you if something wrong with your code.

Next and final step, open your pdf file with a reader that updates the output on file modifications, such as Evince.

And you're good to go, if you have a large screen or a dual monitor setup, you can have your text editor next to your updateed generated PDF file.