Work with Word Documents in PHP


Work with Word Documents in PHP

Open, generate, edit, split, merge, compare and convert a Word document in PHP. It's easy for PHP developers to manipulate Microsoft Word documents. Convert PDF to Word (DOC, DOCX, ODT, RTF and HTML) and in the opposite direction with Aspose Cloud PHP library.

Table of Content

What is Cloud PHP SDK

Aspose.Words Cloud is a modern REST API, designed to perform a wide variety of operations on Word documents in the Cloud. The fundamental idea behind Words Cloud API is to incorporate a full-featured Word document processing functionality into customer’s applications, while providing high scalability and speed.
Similar to other Aspose Cloud SDKs, our PHP Cloud SDK is a wrapper around Cloud API, designed to be simple, efficient and secure. The SDK takes care of low-level details of an underlying REST API architecture, offers fewer opportunities to make mistakes, and lets developers focus on writing code specific to their particular project. As a result, it gets developers up and coding more quickly by putting Cloud API at their fingertips, along with providing PHP code samples and documentation.
For detailed information about the content in this SDK, including a description of new content, please see API Reference.
Also have a look at the complete list of Aspose.Words Cloud SDKs.

Core features and functionality

With PHP Cloud API you can easily integrate Word conversion, generation, and editing features into PHP applications running on any modern OS. It allows you to work with a complete set of Word document components, such as main text, headers, footers, tables, sections, comments, drawing objects, fonts, hyperlinks, math objects, watermarks, and many others. PHP Cloud SDK assists in reading, editing, merging, splitting documents as well as converting a Word document to other supported file formats.

Since all our SDKs have been tested thoroughly before launch, our customers can be assured that PHP Cloud SDK is reliable, secure, and ready for production use in their apps.

You can easily and quickly test the API functionality you are interested in directly from web-browser with Aspose interactive Free Online Apps for Microsoft Word and OpenOffice documents. Have a look at our free online converter, viewer, editor, splitter, merger and other document processing tools.

  • Main
  • Convert
  • Structure
  • Content
  • Tables
  • MailMerge
  • Other
  • Plugins


PHP 7.1 or higher

Supported Document Formats

You can both read and write documents in: DOCX, DOC, PDF, MD, RTF, DOCM, DOTX, DOT, DOTM, ODT, OTT, XML, HTML, MHTML, XHTML, TXT.
The write-only formats are: XPS, OpenXPS, PS, JPEG, PNG, BMP, SVG, TIFF, EMF, PCL, EPUB.
The read-only formats are: MOBI, CHM.
For more details, please check Supported File Formats.


As modern web-based applications increase their flexible interconnected nature more and more, we are paying very close attention to the requirements on the security issues. All our cloud APIs are secured and require JWT token-based authentication.
Before you can make any requests to Aspose Cloud APIs, you need to register an API Client App. This will give you two unique identifiers - Client Id and Client Secret - which you can use to invoke Aspose.Words Cloud APIs.

PHP Cloud SDK Installation

Here go step-by-step instructions:

  1. Download, install and configure PHP 7.1 or higher version on your web-server.
  2. Download and install Composer tool for dependency management in PHP.
  3. Use “composer require aspose-cloud/aspose-words-cloud“ command to install PHP Cloud SDK from Packagist repository.

Getting started with PHP Cloud SDK

So you probably want to jump in and start creating your PHP application right away? The following code samples demonstrate how you would accomplish some typical tasks with the PHP Cloud SDK. You may use the PHP code samples in this section in your scripts and documentation. Also feel free to explore the Developer's Guide for other usage scenarios.
We welcome feedback, so feel free to contact us if you have a problem or question.

Convert PDF to Word in PHP

The following code sample shows how to convert PDF to DOCX in the Cloud and save the result to a local file:

Convert PDF to DOCX
use Aspose\Words\WordsApi;
use Aspose\Words\Model\Requests\ConvertDocumentRequest;

$appSid = "####-####-####-####-####";
$appKey = "##################";
$wordsApi = new WordsApi($appSid, $appKey);

$request = new ConvertDocumentRequest("sample.pdf", "docx");
$result = $wordsApi->convertDocument($request);
// Save an output file as "sample.docx"
rename($result->getPathname(), 'sample.docx');

Advanced Features

How to open and edit 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 existing account.
  4. Click on Applications in the left menu to get Client Id and Client Secret.
  5. Upload a DOCX file to the Cloud Storage or use directly in the request body.
  6. Check Developer Guide to edit a DOCX file in PHP.

Support and Learning Resources