Split PDF via Python for .NET

Split PDF, HTML, TXT files. Use Aspose.PDF for Python for .NET to modify PDF documents programmatically

Split Files Using Aspose.PDF for Python for .NET

Need just part of your large files? To separate one or more parts from your document, you must split the pages of the original file. In order to split files, we’ll use Aspose.PDF for Python 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. Our software tool also provides developers to split Word, PDF, HTML, TXT, and DOCX documents into parts. For more details please learn Documentation Pages. You may also use the following command from the Package Manager Console.

Python Package Manager Console

pip install aspose-pdf

Split documents via Python


You need Aspose.PDF for Python via .NET to try the code in your environment.

  1. Load the PDF with an instance of Document.
  2. Create a new Document class object to split PDF pages.
  3. Add current page to the document.
  4. Save current page as a separate PDF

How to split PDF using Python

With the Aspose.PDF for Python 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

 doc = aspose.pdf.Document("1.pdf")

 pdf_editor = aspose.pdf.PdfFileEditor()
 pdf_editor.Extract(path_source, 1, doc.Pages.Count / 2, "pdf_half.pdf")

How to split HTML files using Python

HTML documents can be large as they can contain text, images, charts, and more. You may need to separate HTML files according to different requirements or use cases. The Aspose.PDF for Python library will help you with this task.

Split HTML - Python

This sample code shows how to split HTML file - Python

 doc = aspose.pdf.Document("test.pdf");

 # save input html to pdf to file
 doc = aspose.pdf.Document("1.html", HtmlLoadOptions);
 doc.Save("test.pdf", SaveFormat.PDF);

 # slit first page
 pdf_editor = aspose.pdf.PdfFileEditor();
 pdf_editor.SplitFromFirst("test.pdf", 1, "test.pdf");
 doc.Save("html_first.html", SaveFormat.HTML);

How to split TXT files using Python

The Aspose.PDF for Python library allows Python developers to split TXT files into separate parts. The function of splitting a TXT document into separate files will help you work with different sections of a large document at the same time and for several users. Splitting a TXT document will speed up and streamline your work. Use the following code snippet to extract the pages of your TXT file.

Split TXT - Python

This sample code shows how to split TXT file - Python

# save input text to pdf to file
doc = aspose.pdf.Document("1.txt", TxtLoadOptions())
doc.Save("test.pdf", SaveFormat.PDF)
index = 1

pages = pdf_editor.SplitToPages("test.pdf")
pdf_editor = aspose.pdf.PdfFileEditor()

for ms in pages:
    page = aspose.pdf.Document(ms)
    text_absorber = aspose.pdf.TextAbsorber()
    page.Pages.Accept(text_absorber)
    extracted_text = text_absorber.Text
    file = open("text_"+str(index)+".txt", "w+")
    file.write(extracted_text)
    index = index + 1

<% splitter.about-content.h2 %>

<% splitter.about-content.text %>