How to Reduce the File Size of a PDF in Node.JS
When working with contracts or other large documents, a PDF is the ideal file format. However, when sharing those same documents, the file size may be too large for email. With this API, you can reduce the size of a PDF file by digitally compressing its contents.
Run this command to install the SDK:
npm install cloudmersive-convert-api-client --save
You can also add this snippet to your package.json:
"dependencies": {
"cloudmersive-convert-api-client": "^2.4.8"
}
Then, you can call the function:
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 inputFile = Buffer.from(fs.readFileSync("C:\\temp\\inputfile").buffer); // File | Input file to perform the operation on.var callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
}
};
apiInstance.editPdfReduceFileSize(inputFile, callback);
With this, you can ensure that all of your files can be effectively and efficiently shared with all necessary parties.
You can retrieve the API Key from the Cloudmersive website at no cost and with no commitment. This will provide you with 800 monthly calls across our library of APIs.