How to convert Excel XLSX to PDF in PHP
1 min readJul 3, 2019
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.