Split PDF via Python via C++

Split PDF, HTML, TXT files. Use Aspose.PDF for Python via C++ to modify PDF documents programmatically

Split Files Using Aspose.PDF for Python via C++

In order to split files, we’ll use Aspose.PDF API which is a feature-rich, powerful and easy-to-use document manipulation API for python-cpp platform. Open NuGet package manager, search for Aspose.PDF and install. You may also use the following command from the Package Manager Console. Our software tool also provides developers to split Word, PDF, HTML, TXT, and DOCX documents into parts. For more details please learn Documentation Pages.

Split documents via Python


You need Aspose.PDF library to try the code in your environment.

  1. Create an object and load PDF.
  2. Create a page counter.
  3. Start a loop that goes through each page in the document object.
  4. Save split pages

How to split PDF using Python

With the Aspose.PDF library, you can split large PDF documents. Splitting a PDF document is a common use case when working with PDF documents. It helps reduce the size of a PDF file by breaking large documents into smaller files to send via email.

Split PDF - Python

This sample code shows how to split PDF file - Python

import AsposePDFPythonWrappers as apw

document = apw.Document("sample.pdf")

pageCount = 1

for page in document.pages:
    newDocument = apw.Document()
    newDocument.pages.add(page)
    newDocument.save("page_" + pageCount + "_out" + ".pdf")
    pageCount += 1