Add Pages in PDF with Python
Aspose.PDF for Python via .NET API provides full flexibility to work with pages in a PDF document using Python. It maintains all the pages of a PDF document in PageCollection that can be used to work with PDF pages. Aspose.PDF for Python via .NET lets you insert a page to a PDF document at any location in the file as well as add pages to the end of a PDF file. This section shows how to add pages to a PDF using Python.
Add or Insert Page in a PDF File
Aspose.PDF for Python via .NET lets you insert a page to a PDF document at any location in the file as well as add pages to the end of a PDF file.
Insert Empty Page in a PDF File at Desired Location
To insert an empty page in a PDF file:
- Create a Document class object with the input PDF file.
- Call the PageCollection collection’s insert method with specified index.
- Save the output PDF using the save method.
The following code snippet shows you how to insert a page in a PDF file.
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)
Add an Empty Page at the End of a PDF File
Sometimes, you want to ensure that a document ends on an empty page. This topic explains how to insert an empty page at the end of the PDF document.
To insert an empty page at the end of a PDF file:
- Create a Document class object with the input PDF file.
- Call the PageCollection collection’s add() method, without any parameters.
- Save the output PDF using the save() method.
The following code snippet shows you how to insert an empty page at the end of a PDF file.
import aspose.pdf as ap
# Open document
document = ap.Document(input_pdf)
# Insert an empty page at the end of a PDF file
document.pages.add()
# Save output file
document.save(output_pdf)