How to convert any Document File into PNG Array in PHP

Cloudmersive
2 min readApr 15, 2020

Here we will be showing how to turn any document file into a set of PNGs. Among other reasons, this guarantees compatibility, given the universal nature of PNG format. I’m also going to guarantee that this method can be completed faster than any other — five minutes or less, in fact. Let’s go!

We begin by using this command for composer, which will install our API client when run from the command line.

composer require cloudmersive/cloudmersive_document_convert_api_client

Now it’s time to call convertDocumentAutodetectToPngArray:

<?phprequire_once(__DIR__ . '/vendor/autoload.php');// Configure API key authorization: Apikey$config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKey('Apikey', 'YOUR_API_KEY');// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed// $config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKeyPrefix('Apikey', 'Bearer');$apiInstance = new Swagger\Client\Api\ConvertDocumentApi(// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.// This is optional, `GuzzleHttp\Client` will be used as default.new GuzzleHttp\Client(),$config);$input_file = "/path/to/file"; // \SplFileObject | Input file to perform the operation on.try {$result = $apiInstance->convertDocumentAutodetectToPngArray($input_file);print_r($result);} catch (Exception $e) {echo 'Exception when calling ConvertDocumentApi->convertDocumentAutodetectToPngArray: ', $e->getMessage(), PHP_EOL;}?>

Alright, that’s done with. Really simple. Just input a document to be converted. The format will be automatically detected by the API, then a set of links will be provided, which correspond to the PNG files for download.

--

--

Cloudmersive

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