How to set PDF Metadata in PHP

The typical process for setting up PDF metadata editing in PHP is a bit of a chore. But the method that I’m going to show you today is as easy as 1, 2, 3! Here’s a quick rundown.

  1. Install our API client, using the following command.
composer require cloudmersive/cloudmersive_document_convert_api_client

2. Call this function:

<?phprequire_once(__DIR__ . '/vendor/autoload.php');// Configure API key authorization: Apikey$config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKey('Apikey', 'YOUR_API_KEY');// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed// $config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKeyPrefix('Apikey', 'Bearer');$apiInstance = new Swagger\Client\Api\EditPdfApi(// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.// This is optional, `GuzzleHttp\Client` will be used as default.new GuzzleHttp\Client(),$config);$request = new \Swagger\Client\Model\SetPdfMetadataRequest(); // \Swagger\Client\Model\SetPdfMetadataRequest |try {$result = $apiInstance->editPdfSetMetadata($request);print_r($result);} catch (Exception $e) {echo 'Exception when calling EditPdfApi->editPdfSetMetadata: ', $e->getMessage(), PHP_EOL;}?>

3. Input your desired PDF file and corresponding metadata into editPdfSetMetadata.

That’s it! Seriously, that’s the entire process. So easy!

Image for post
Image for post

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