How to extract PDF Metadata in PHP

I’m going to take a wild guess and say that you are not keenly disposed toward coding out a solution for obtaining PDF metadata. That’s why you’re here, isn’t it? That’s OK, it’s not a very interesting subject. But do you know what makes it more palatable? An API that does it all for you! Let’s get straight to that.

We begin by installing our API client with this composer command.

composer require cloudmersive/cloudmersive_document_convert_api_client

After installation, we move on to calling this function for PDF metadata:

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

Well, there it is, our completed solution. You have only to input your PDF file and let the metadata extraction begin!

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