How to convert a PDF to PNG array in PHP
1 min readAug 2, 2019
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.