Add Pages to PDF using Python

Insert pages to PDF document programmatically using Aspose.PDF for Python for .NET Library

How to Add pages to PDF Using Python

In order to insert page in PDF file, we’ll use Aspose.PDF for .NET 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

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

Insert New Page to PDF


import aspose.pdf as ap

# Open document
document = ap.Document(input_pdf)
# Insert a empty page in a PDF
document.pages.insert(2)
# Save output file
document.save(output_pdf)