Manipulating PDFs (adding header/footer, merge, split, delete)
Ever wondered if you could merge PDF files programatically in a few seconds? Or could update header and footer of many PDF files in a jiffy? In this recipe, lets move on to do some interesting and most frequently performed operations on PDF files in this recipe.
For this recipe, we will use the
fpdf modules that were installed for the earlier recipes.
How to do it...
- Let's start by working with the
PdfFileMergeclass of the
PyPDF2. We use this class to merge multiple PDF files. The following code example does exactly the same:
from PyPDF2 import PdfFileReader, PdfFileMerger import os merger = PdfFileMerger() files = [x for x in os.listdir('.') if x.endswith('.pdf')] ...