How to Resize a PDF File in PHP

Cloudmersive
1 min readFeb 19, 2021

--

Looking to resize a PDF for a project? If so, we have an API that can fit your needs. Using the PHP programming language, the following API can resize a PDF file to the input paper size; sizes run from A7 (smallest) to A0 (largest).

Our first step is to run this command to install the client:

composer require cloudmersive/cloudmersive_document_convert_api_client

Next, we can create an instance of the API and call the resize function:

<?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.
$paper_size = "paper_size_example"; // string | The desired paper size for the resized PDF document. Size ranges from A7 (smallest) to A0 (largest).
try {
$result = $apiInstance->editPdfResize($input_file, $paper_size);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling EditPdfApi->editPdfResize: ', $e->getMessage(), PHP_EOL;
}
?>

In no time at all, your PDF has been tailored to meet your measurements. To retrieve your free API key, simply head to the Cloudmersive website to gain access to 800 monthly calls across our library of APIs.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet