O'Reilly logo

Automate it! - Recipes to upskill your business by Chetan Giridhar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required