This sample source code can be used to convert PDF to image(JPEG, PNG, TIFF) in PHP using ByteScout Cloud API (low level). You can set such parameters as image resolution, quality, and image output format.
You can also find PDF to Image conversion code samples for other languages here: Java, jQuery, and pure JavaScript.
https://api.pdf.co/v1/pdf/convert/to/jpg
<?php require_once(__DIR__ . '/vendor/autoload.php'); // Configure API key authorization: api_key Bytescout\Client\API\Configuration::getDefaultConfiguration()->setApiKey('x-api-key', 'YOUR_API_KEY'); // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // Bytescout\Client\API\Configuration::getDefaultConfiguration()->setApiKeyPrefix('x-api-key', 'Bearer'); $api_instance = new Swagger\Client\Api\DefaultApi(); $pages = pages_example; // String | Comma-separated list of page indices (or ranges) to process. Leave empty for all pages. Example: '0,2-5,7-'. $name = name_example; // String | File name for generated result. $url = url_example; // String | URL of the source PDF file. try { $result = $api_instance->pdfConvertToJpgPost($pages, $name, $url); print_r($result); } catch (Exception $e) { echo 'Exception when calling DefaultApi->pdfConvertToJpgPost: ', $e->getMessage(), PHP_EOL; } ?>
https://api.pdf.co/v1/pdf/convert/to/png
<?php require_once(__DIR__ . '/vendor/autoload.php'); // Configure API key authorization: api_key Bytescout\Client\API\Configuration::getDefaultConfiguration()->setApiKey('x-api-key', 'YOUR_API_KEY'); // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // Bytescout\Client\API\Configuration::getDefaultConfiguration()->setApiKeyPrefix('x-api-key', 'Bearer'); $api_instance = new Swagger\Client\Api\DefaultApi(); $pages = pages_example; // String | Comma-separated list of page indices (or ranges) to process. Leave empty for all pages. Example: '0,2-5,7-'. $name = name_example; // String | File name for generated result. $url = url_example; // String | URL of the source PDF file. try { $result = $api_instance->pdfConvertToPngPost($pages, $name, $url); print_r($result); } catch (Exception $e) { echo 'Exception when calling DefaultApi->pdfConvertToPngPost: ', $e->getMessage(), PHP_EOL; } ?>
https://api.pdf.co/v1/pdf/convert/to/tiff
<?php require_once(__DIR__ . '/vendor/autoload.php'); // Configure API key authorization: api_key Bytescout\Client\API\Configuration::getDefaultConfiguration()->setApiKey('x-api-key', 'YOUR_API_KEY'); // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // Bytescout\Client\API\Configuration::getDefaultConfiguration()->setApiKeyPrefix('x-api-key', 'Bearer'); $api_instance = new Swagger\Client\Api\DefaultApi(); $pages = pages_example; // String | Comma-separated list of page indices (or ranges) to process. Leave empty for all pages. Example: '0,2-5,7-'. $name = name_example; // String | File name for generated result. $url = url_example; // String | URL of the source PDF file. try { $result = $api_instance->pdfConvertToTiffPost($pages, $name, $url); print_r($result); } catch (Exception $e) { echo 'Exception when calling DefaultApi->pdfConvertToTiffPost: ', $e->getMessage(), PHP_EOL; } ?>
IMPORTANT:
Cloud API is deprecated and was replaced with more powerful and secure www.PDF.co Web API
CLICK HERE
TO LEARN MORE
ABOUT NEW
www.PDF.co
w/ Web API
On-Premise API Server
Cloud API Server