How to set PDF Metadata in Node.JS

Today we will be creating a system for Node.JS by which we can set the metadata for PDF files. You really dodged a bullet by coming to this tutorial, as we will be eluding the dreaded task of coding this functionality. Indeed, we will be doing very little work at all to set this up. Here’s how.

By adding this reference to our package.json file, we can begin installation of our API client.

"dependencies": {
"cloudmersive-convert-api-client": "^2.1.6"
}

And the next step is a function call for editPdfSetMetadata:

var CloudmersiveConvertApiClient = require('cloudmersive-convert-api-client');var defaultClient = CloudmersiveConvertApiClient.ApiClient.instance;// Configure API key authorization: Apikeyvar Apikey = defaultClient.authentications['Apikey'];Apikey.apiKey = 'YOUR API KEY';// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)//Apikey.apiKeyPrefix = 'Token';var apiInstance = new CloudmersiveConvertApiClient.EditPdfApi();var request = new CloudmersiveConvertApiClient.SetPdfMetadataRequest(); // SetPdfMetadataRequest |var callback = function(error, data, response) {if (error) {console.error(error);} else {console.log('API called successfully. Returned data: ' + data);}};apiInstance.editPdfSetMetadata(request, callback);

And there you have it. You can now add in whatever kind of metadata you wish into your PDFs. No problem.

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