How to Rasterize a PDF using PHP

Cloudmersive
2 min readFeb 22, 2023

--

Rasterization is a simple, easy process to use when we want to ensure our vector PDF documents can’t be easily converted and edited by an unwanted third party.

With the ready-to-run PHP code examples provided below, you can quickly implement a PDF rasterization API into your file processing application. Calling this API will remove all text, figures and additional components from your vector PDF file and replace them with high resolution images of each page’s contents. Please note that this operation, by design, can’t be directly reversed (you could, however, use OCR to process text components from the raster images, which would result in plain text with no original formatting).

You can install the PHP SDK by running this command:

composer require cloudmersive/cloudmersive_document_convert_api_client

And you can complete your API call using the remaining PHP code examples:

<?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\EditPdfApi(


new GuzzleHttp\Client(),
$config
);
$input_file = "/path/to/inputfile"; // \SplFileObject | Input file to perform the operation on.

try {
$result = $apiInstance->editPdfRasterize($input_file);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling EditPdfApi->editPdfRasterize: ', $e->getMessage(), PHP_EOL;
}
?>

Make sure to include a valid Cloudmersive API key with your request (you can get one for free by registering a free account on our website), and you’re all set!

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet