How to convert PowerPoint PPTX to PDF in PHP

Cloudmersive
1 min readJul 14, 2019

--

The first step for us is to add a reference to the package in composer.json, our package manager, to the document processing library:

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

Now, we simply need to the X function to convert a PowerPoint (PPTX) presentation into a PDF file in PHP:

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

That’s all we need to do, and it was free. The resulting output will be the bytes of the PDF file. We can store this in a database, cache it, render it to the user, or write it to disk. We are done — and best of all, this library produces very high fidelity conversions with support for all the extensive nuances of PowerPoint file formats, such as shapes and formatting. We can also leverage a different function for PPT files (the legacy PowerPoint file format).

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

Responses (1)