How to validate a PowerPoint PPTX Presentation in PHP

Cloudmersive
1 min readJul 16, 2019

--

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:

<?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\ValidateDocumentApi(


new GuzzleHttp\Client(),
$config
);
$input_file = "/path/to/file.pptx"; // \SplFileObject | Input file to perform the operation on.
try {
$result = $apiInstance->validateDocumentPptxValidation($input_file);
print_r($result);
} 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.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet