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.

Getting ready

For this recipe, we will use the PyPDF2 and fpdf modules that were installed for the earlier recipes.

How to do it...

  1. Let's start by working with the PdfFileMerge class 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')] ...

Get Automate it! - Recipes to upskill your business now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.