Convert Word Documents in PHP

Convert Word Documents in PHP

Converting documents in PHP is an easy to use API to convert Word, PDF and other file formats.
Cloud API has many convert features, such as:

  • Convert PDF to Word, JPG, HTML, etc.
  • Convert multiple DOCX files.
  • DOCX to DOC which converts the latest Word format into the old format and vice versa.
Note: As a prerequisite, you need PHP and Words Cloud PHP library installed on your computer.

Conversion features

Aspose Cloud provides a powerful file conversion REST API to convert files in PDF, images and many other supported file formats.
PHP Cloud API creates converted documents according to the specifications of the targeted file format. It generates an output file within native tools.

Convert PDF to Word

PHP API helps to convert PDF to a Word document or other supported file formats.

Extract text from PDF

If you need to extract text from PDF just convert it to TXT file.

Convert Word to PDF

Use PHP API to convert a Word document to PDF. The output file conforms to PDF 1.5 or PDF/A-1b specifications.
Get the same high-fidelity page layout of the rendering engine to produce output in a fixed-layout format.

Convert Word to TXT

Extract text easily by using PHP API when converting a Word document to a TXT file.

Convert Word to EPUB

PHP API allows to convert Word documents to EPUB files.
Word document content, formatting, images, hyperlinks and navigation will work in any EPUB reader.

Convert DOCX to image

You can easily convert a DOCX document to a different image file format with the highest degree of image quality in PHP. Conversion supports raster formats (JPG, GIF, PNG, etc.) and vector formats (SVG, EMF, etc.).
Save each page of the document as any supported image file format.

Why convert a Word document using PHP?

There are many reasons to convert Word DOC to PDF or other file formats:

  • References can become mismatched.
  • Word documents don’t keep their formatting.
  • Word has multiple versions.
  • Other file formats like PDF files which are mobile-friendly.

What does PHP conversion API do?

  • Converts document from request content to a specified format.
  • Convert a document to another file format with detailed settings and save the result to Cloud storage.
  • Keep style and layout of the source document.

Where and how?

Luckily for you, Aspose.Words Cloud API has the answer.
The ability to convert documents from one format to another is one of four main feature areas of Aspose.Words Cloud. It provides the following simplest APIs to convert a Word document to other file formats.

Getting Started

How to Convert a DOCX document in PHP

  1. Go to the Aspose Cloud Dashboard.
  2. Create a new Account to access all applications and services or Sign In to your account.
  3. Click on My Apps tab.
  4. Get App Key and App SID.
  5. Check API Reference page for the description of APIs parameters.
  6. Install PHP SDK library via composer.
  7. Check Developer Guide to convert DOCX to PDF, EPUB, JPG, etc.

Convert documents in PHP
use Aspose\Words\Model;
use Aspose\Words\Model\Requests;
use Aspose\Words\WordsApi;

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

// Convert PDF to Word
$request = new Requests\ConvertDocumentRequest("sample.pdf", "docx");
$result = $wordsApi->convertDocument($request);
// Save the result to a local file
rename($result->getPathname(), 'sample.docx');

// Convert DOCX to PDF if we have a document in the Storage
$saveOptions = new Model\SaveOptionsData(array(
	"file_name" => "dest.pdf", "save_format" => "pdf"));
$request = new Requests\SaveAsRequest('source.docx', $saveOptions);
$wordsApi->saveAs($request);

// Convert DOCX to HTML with advanced options
$saveOptions = new Model\HtmlFixedSaveOptionsData(array(
    "export_embedded_css" => true, "css_class_names_prefix"=>"aspose_",
    "page_index" => 2, "page_count"=>3, "jpeg_quality" => 90,
    "file_name" => "sample.html", "save_format" => "html"
));
$request = new Requests\SaveAsRequest("sample.docx", $saveOptions);
$result = $wordsApi->saveAs($request);