Learn how to Add Pages to PDF in Python
Created
October 31, 2025 01:51
-
-
Save aspose-com-gists/8f475f437c76c17e522714ec1e10230f to your computer and use it in GitHub Desktop.
Add Pages to PDF in Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import aspose.pdf as pdf | |
| # Create a new PDF document | |
| doc = pdf.Document() | |
| # Add multiple blank pages | |
| for i in range(5): | |
| doc.pages.add() | |
| # Save the final PDF | |
| doc.save("multiple_pages.pdf") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import aspose.pdf as pdf | |
| # Load the existing PDF document | |
| document = pdf.Document("input.pdf") | |
| # Add a new blank page | |
| document.pages.add() | |
| # Save the updated PDF | |
| document.save("output_add_page.pdf") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import aspose.pdf as pdf | |
| # Load the first and second PDF documents | |
| first_pdf = pdf.Document("input.pdf") | |
| second_pdf = pdf.Document("source.pdf") | |
| # Add all pages from second_pdf into first_pdf | |
| first_pdf.pages.add(second_pdf.pages) | |
| # Save the merged document | |
| first_pdf.save("combined.pdf") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import aspose.pdf as pdf | |
| # Load the destination PDF | |
| destination = pdf.Document("input.pdf") | |
| # Load the source PDF that contains the page to insert | |
| source = pdf.Document("source.pdf") | |
| # Insert the first page of the source PDF at position 1 in the destination PDF | |
| destination.pages.insert(1, source.pages[1]) | |
| # Save the updated document | |
| destination.save("output_insert_page.pdf") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import aspose.pdf as pdf | |
| # Load the PDF document | |
| doc = pdf.Document("input.pdf") | |
| # Insert the page at position 2 | |
| doc.pages.insert(2) | |
| # Save the updated document | |
| doc.save("output_specific_insert.pdf") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment