Aggregating PDF reports
In this recipe, we'll see how to combine two PDFs into one. We will add the pages of one report at the end of the other.
Getting ready
We'll use the PyPDF2 module. Pillow and pdf2image are also dependencies used by the scripts:
$ echo "PyPDF2==1.26.0" >> requirements.txt
$ echo "pdf2image==1.11.0" >> requirements.txt
$ echo "Pillow==7.0.0" >> requirements.txt
$ pip install -r requirements.txt
For pdf2image to properly work, it needs to install pdftoppm, so check here for instructions on how to install it for different platforms: https://github.com/Belval/pdf2image#first-you-need-pdftoppm.
We need two PDFs to combine them. For this recipe, we'll use two PDFs: a report.pdf file generated by the structuring_pdf.py script, available on GitHub: https://github.com/PacktPublishing/Python-Automation-Cookbook-Second-Edition/blob/master/Chapter05/structuring_pdf.py, and another (report2...