How to validate a PowerPoint PPTX Presentation in PHP

Here, we want to check if an input PowerPoint PPTX file is indeed valid. For example, our website may allow users to input PowerPoint files and we need to check if the files are truly valid before accepting them.

First, we need to add a reference to the library to our composer.json:

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

Now, all we need to do is call the validateDocumentPptxValidation 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\ValidateDocumentApi(

new GuzzleHttp\Client(),
$input_file = "/path/to/file.pptx"; // \SplFileObject | Input file to perform the operation on.
try {
$result = $apiInstance->validateDocumentPptxValidation($input_file);
} catch (Exception $e) {
echo 'Exception when calling ValidateDocumentApi->validateDocumentPptxValidation: ', $e->getMessage(), PHP_EOL;

That’s it! Now our result object contains DocumentIsValid which will be true if the document is a valid PowerPoint presentation and false otherwise. We can even get the errors and warnings from the appropriate fields in the object.

Now we have a high-confidence, high-fidelity result that we can use in our application.

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