Split Word Documents in Python

Split Word Documents in Python

Words Cloud Python SDK provides an easy to use API to split DOCX, RTF, ODT and other file formats.
Cloud API has many split page features, such as:

  • Split pages no matter the length or file size.
  • Split page range.
  • Save as PDF, JPG, HTML, etc.

Overview

Use Python to split a Word document into multiple smaller files, or to extract pages to a new file.

Tip: Merging different Word documents is also possible.

Note: As a prerequisite, you need Python and Words Cloud Python SDK installed on your computer.

Why split a Word document using Python?

While working with your documents, you may come across scenarios where you want to split large documents into smaller ones.
When scanning books, images or articles, you need to do it fast and all together. But in the end, you may want to separate pages of a Word document or any other document.
By splitting a document, you don’t need to send or print information you don’t want to.

What does split API for Python do?

  • Multi-page Word documents are divided into separate Word documents.
  • Split operation divides a multi-page Word document by page number, odd/even pages and by page range (entering the page range can be divided according to the page number of documents).
  • Split one big file into many smaller, one-page files. You can split them into multiple files, in various page ranges.
  • Keep style and layout of the source document.

Where and how?

Luckily for you, Words Cloud API has the answer.
The ability to split documents is one of four main feature areas of Words Cloud. It provides the simplest API to split a Word document within MS Word documents or other file formats.
Using an API client is the quickest way for a Python developer to speed up the development. API takes care of low-level details to make requests and handle responses. And this lets you focus on writing code specific to your particular project.

Getting Started

How to Split a DOCX document in Python

  1. Install Python SDK.
  2. Go to the Aspose Cloud Dashboard.
  3. Create a new Account to access all applications and services or Sign In to your account.
  4. Click on Applications in the left menu to get Client Id and Client Secret.
  5. Check Developer Guide to split a DOCX file in Python.
  6. Check API Reference page for the description of APIs parameters.

Split a Word document in Python
import asposewordscloud
from asposewordscloud.models.requests import SplitDocumentRequest

app_sid = '####-####-####-####-####'
app_key = '##################'
words_api = WordsApi(app_sid, app_key)

# Split all pages and save to PDF
request = SplitDocumentRequest('sample.docx', format='pdf')
words_api.split_document(request)

# Split page range 2-5 and save to JPEG
request = SplitDocumentRequest('sample.docx', format='jpeg', _from=2, to=5)
words_api.split_document(request)

# Split all pages, save to HTML and zip output files
request = SplitDocumentRequest('sample.docx', format='html', zip_output=True)
words_api.split_document(request)


  

Support and Learning Resources