Creating and copying PDF documents

Working with PDFs adds more value when you can create them from scratch programmatically. Let's see how we can create our own PDF files in this section.

Getting ready

We will continue to use the PyPDF2 module for this recipe and will deal with its PdfFileWriter and PdfFileMerger classes. We will also use another module, fpdf, to demonstrate adding content to PDF files. We will talk about this later in the recipe.

How to do it...

  1. We can create a PDF file in multiple ways; in this example, we copy the contents of an old file to generate a new PDF file. We start by taking an existing PDF--Exercise.pdf. The following screenshot shows the contents of this file. It contains two pages; the first page is a technical exercise ...

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.