How to Get Macro Info from a DOCX File in PHP
Macros are essentially code that you can build into applications or documents that can automate repetitive tasks and contribute to an increase in productivity and the simplification of processes. One of the only downsides to macros is that they can pose a security risk if you didn’t build them yourself. Utilizing the following API in PHP, you can retrieve information about the macros defined in a DOCX file, enabling you to evaluate the file’s safety.
To use the API, first run this command to install the SDK:
composer require cloudmersive/cloudmersive_document_convert_api_client
Once the installation is complete, we’re all set to call our get macro 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\EditDocumentApi(
new GuzzleHttp\Client(),
$config
);
$input_file = "/path/to/inputfile"; // \SplFileObject | Input file to perform the operation on.try {
$result = $apiInstance->editDocumentDocxGetMacroInformation($input_file);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling EditDocumentApi->editDocumentDocxGetMacroInformation: ', $e->getMessage(), PHP_EOL;
}
?>
If the operation runs successfully, you will be provided with information on any identified macros within your Word document.