How to Convert Bitmap to PDF in PHP

Cloudmersive
2 min readMay 6, 2024

Converting Bitmap (BMP) files to PDF is easy — we just need to implement a free, low-code PDF conversion API into our workflow.

We can easily structure our API call using ready-to-run PHP code examples provided further down the page. The API we’re using will automatically detect the input BMP image and make a high-quality PDF conversion, returning the PDF encoding in the API response.

If we’re looking to convert other image formats to PDF in the same process, this API will take care of that as well. It’s equipped to handle 100+ common image formats, including the likes of JPG and PNG.

To begin structuring our API call, let’s first install the PHP client. We can install with Composer by executing the below command from the command line:

composer require cloudmersive/cloudmersive_document_convert_api_client

Next, let’s quickly turn our attention to API call authorization. We’ll need a free Cloudmersive API key to authorize our requests (this will allow us to make a limit of 800 API calls per month with no additional commitments).

With our API key ready to go, we can copy the below code to call the function, and we can supply our API key in the $config snippet:

<?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/inputfile"; // \SplFileObject | Input file to perform the operation on.

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

And that’s all there is to it! Now we can easily convert Bitmap images to PDF documents using minimal code.

--

--

Cloudmersive

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