How to Convert DOCX Documents to PNG Images in PHP
Creating a PNG image of a DOCX file results in a static version of that document’s contents which cannot be changed or manipulated, and which can be viewed on any operating system. On top of that, this process offers lightweight storage redundancy for large DOCX files, making them easier to share and archive.
Using the code provided below, you can quickly & easily implement a multi-page DOCX to PNG Image Array conversion API into your PHP applications. You can use this API for free, too (with a limit of up to 800 API calls per month) — just register a free account on our website and include your free-tier API key with your request.
To install the SDK, first run this command:
composer require cloudmersive/cloudmersive_document_convert_api_client
After that, call the function:
<?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\ConvertDocumentApi(
new GuzzleHttp\Client(),
$config
);
$input_file = "/path/to/inputfile"; // \SplFileObject | Input file to perform the operation on.
try {
$result = $apiInstance->convertDocumentDocxToPng($input_file);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling ConvertDocumentApi->convertDocumentDocxToPng: ', $e->getMessage(), PHP_EOL;
}
?>
Just like that, you’re all done — no more code required. Fast and easy!