How to Set PDF Document Metadata using Node.js
--
The more control we have over the metadata of our PDF documents, the greater the impact those documents can make.
By efficiently using APIs to manipulate our PDF documents’ details, we can make significant improvements to our document’s visibility and accessibility on the internet. Just as importantly, we can improve our documents’ indexing internally in our own web application databases.
Using the below code, we can take advantage of a free API that allows us to completely set any PDF document’s metadata (processed in-memory; data is released upon task completion). This makes it possible to change our document’s author, subject, keywords, and much more, all in a single request.
We can begin to structure our API call by first running the following command to install the SDK:
npm install cloudmersive-convert-api-client --save
Or we can accomplish the same by adding the following snippet to our package.json:
"dependencies": {
"cloudmersive-convert-api-client": "^2.6.3"
}
Next, we can copy the below ready-to-run code examples to structure our request. We won’t need to worry about any request parameters, but we will need to authorize our requests with a free-tier API key (obtainable by registering a free account on the Cloudmersive website) to make up to 800 API calls per month with no commitments:
var CloudmersiveConvertApiClient = require('cloudmersive-convert-api-client');
var defaultClient = CloudmersiveConvertApiClient.ApiClient.instance;
// Configure API key authorization: Apikey
var Apikey = defaultClient.authentications['Apikey'];
Apikey.apiKey = 'YOUR API KEY';
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);