Split Word Documents in PHP

Split Word Documents in PHP

Words Cloud PHP 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.


Use PHP 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 PHP and Words Cloud PHP library installed on your computer.

Why split a Word document using PHP?

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 PHP 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 PHP 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 PHP

  1. Install PHP SDK library via composer.
  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 PHP.
  6. Check API Reference page for the description of APIs parameters.

Split a Word document in PHP
use Aspose\Words\Model\Requests;
use Aspose\Words\WordsApi;

$appSid = "####-####-####-####-####";
$appKey = "##################";
$wordsApi = new WordsApi($appSid, $appKey);
// Split all pages and save to PDF
$request = new Requests\SplitDocumentRequest("sample.docx",  "pdf");

// Split page range 2-5 and save to JPEG
$request = new Requests\SplitDocumentRequest("sample.docx", "jpeg", null, null, null, null, null, 2, 5);

// Split all pages, save to HTML and zip output files
$request = new Requests\SplitDocumentRequest("sample.docx", "html", null, null, null, null, null, null, null, true);


Support and Learning Resources