How to convert Excel XLSX to PDF in PHP

The first thing we need to do is add a reference to the library in our composer.json:

"require": {
"cloudmersive/cloudmersive_document_convert_api_client": "^1.4",
}

Now all we need to do is call the convertDocumentXlsxToPdf method to convert the XLSX file into PDF:

<?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/file.xlsx"; // \SplFileObject | Input file to perform the operation on.
try {
$result = $apiInstance->convertDocumentXlsxToPdf($input_file);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling ConvertDocumentApi->convertDocumentXlsxToPdf: ', $e->getMessage(), PHP_EOL;
}
?>

That’s all there is to it! Now we will have a high-fidelity conversion of the XLSX file with all of the details and rendering elements correct.

Written by

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

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store