Work with Pages in PDF using Python

Manage PDF pages in document programmaticaly using Aspose.PDF for Python for .NET Library

Most popular action with Pages in Python

How to Insert pages to PDF Document using Python

In order to add page in PDF file, we’ll use Aspose.PDF for Python API which is a feature-rich, powerful and easy to use document manipulation API for python-net platform. Open NuGet package manager, search for Aspose.PDF and install. You may also use the following command from the Package Manager Console.

Console

pip install aspose-pdf

Add Page to PDF using Python


You need Aspose.PDF for Python via .NET to try the code in your environment.

  1. Create a Document object with the input PDF file.

  2. Call the PageCollection collection’s Insert method with specified index.

  3. Save the output PDF using the Save method.

Add New Page to PDF

import aspose.pdf as apdf

from os import path

path_infile = path.join(self.data_dir, infile)
path_outfile = path.join(self.data_dir, outfile)

document = apdf.Document(path_infile)
document.pages.insert(2)
document.save(path_outfile)