How to Convert PDF to Image in PHP using Cloud API (low level) - ByteScout

How to Convert PDF to Image in PHP using Cloud API (low level)

  • Home
  • /
  • Articles
  • /
  • How to Convert PDF to Image in PHP using Cloud API (low level)

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.

PDF to JPEG

POST/GET endpoint:

https://api.pdf.co/v1/pdf/convert/to/jpg

Code Sample (PDF to JPEG):

<?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;
}
?>

PDF to PNG

POST/GET endpoint:

https://api.pdf.co/v1/pdf/convert/to/png

Code Sample (PDF 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;
}
?>

PDF to TIFF

POST/GET endpoint:

https://api.pdf.co/v1/pdf/convert/to/tiff

Code Sample (PDF 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;
}
?>

Tutorials:

prev
next