How to convert HTML to a Word DOCX Document in PHP

Our Convert API is about to make your life very easy. Two steps, here we go.

Add a library reference as you see here:

"require": {
"cloudmersive/cloudmersive_document_convert_api_client": "^1.4",
}

And then just use convertWebHtmlToDocx:

<?php
require_once(__DIR__ . '/vendor/autoload.php');
// Configure API key authorization: Apikey
$config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKey('Apikey', 'YOUR_API_KEY');
$apiInstance = new Swagger\Client\Api\ConvertWebApi(


new GuzzleHttp\Client(),
$config
);
$input_request = new \Swagger\Client\Model\HtmlToOfficeRequest(); // \Swagger\Client\Model\HtmlToOfficeRequest |
try {
$result = $apiInstance->convertWebHtmlToDocx($input_request);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling ConvertWebApi->convertWebHtmlToDocx: ', $e->getMessage(), PHP_EOL;
}
?>

Yup, it’s that simple. Also note that this function supports images (as long as they have qualified URLs) and styling.

Written by

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store