How to convert HTML to a Word DOCX Document in PHP

Cloudmersive
1 min readJul 31, 2019

--

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.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet