How to convert a PDF to PNG array in PHP

Let us begin by referencing our API in our library.

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

Then we need to call convertDocumentPdfToPngArray as you see here:

<?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/file"; // \SplFileObject | Input file to perform the operation on.
try {
$result = $apiInstance->convertDocumentPdfToPngArray($input_file);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling ConvertDocumentApi->convertDocumentPdfToPngArray: ', $e->getMessage(), PHP_EOL;
}
?>

Our return will consist JSON with URLs to the corresponding PNGs, which can then be downloaded. Simple.

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