Convert an XLSX File to PDF in PHP

2 min readFeb 19, 2021

Do you need to share complex data with a client or colleagues? If so, chances are you’ve organized the information into an Excel spreadsheet, the most compatible format for manipulating numbers and sets into an easy to digest display.

However, while Excel is the perfect source format for this type of information, it is not ideal for sharing; the format that wins the most shareable title is the PDF document. The following API will allow you to quickly and efficiently transform your entire Excel workbook into a more versatile PDF document.

To start the conversion process, we first need to install the client:

composer require cloudmersive/cloudmersive_document_convert_api_client

Once the installation is complete, we can move on to creating an instance of the API and calling the function:

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

By the end of the run, you will have a new PDF file that you can feel confident to share with anyone as needed!




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