Split PDF programmatically in Python
Contents
[
Hide
]
Splitting PDF pages can be a useful feature for those who want to split a large file into separate pages or groups of pages.
Live Example
Aspose.PDF Splitter is an online free web application that allows you to investigate how presentation splitting functionality works.
This topic shows how to split PDF pages into individual PDF files in your Python applications. To split PDF pages into single page PDF files using Python, the following steps can be followed:
- Loop through the pages of PDF document through the Document object’s PageCollection collection
- For each iteration, create a new Document object and add the individual Page object into the empty document
- Save the new PDF using save() method
Split PDF into multiple files or separate pdfs in Python
The following Python code snippet shows you how to split PDF pages into individual PDF files.
import aspose.pdf as ap
# Open document
document = ap.Document(input_pdf)
page_count = 1
# Loop through all the pages
for pdfPage in document.pages:
new_document = ap.Document()
new_document.pages.add(pdfPage)
new_document.save(output_path + "_page_" + str(page_count) + ".pdf")
page_count = page_count + 1