How to Resize a PDF Document for Print in Node.JS

Cloudmersive
2 min readOct 29, 2020

--

The PDF file format is widely used across document genres due to its flexibility and array of editing, encryption, and conversion capabilities. Because this file format is commonly employed for sharing and printing all kinds of documents, it may occasionally be necessary to resize printing parameters to meet the needs of each document. For example, a blueprint for a construction project may need to be printed on larger sheets for easier reading, while an invitation or brochure would require a smaller paper size. The following API will allow you to instantly adjust the paper size of a PDF document to meet your project’s needs. The required input needed to run the function is the input PDF file as well as the desired paper size. The sizes run from A7 (the smallest) to A0 (the largest).

To use this API, run the following command to install the SDK:

npm install cloudmersive-convert-api-client --save

Or, you can 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 paperSize = "paperSize_example"; // String | The desired paper size for the resized PDF document. Size ranges from A7 (smallest) to A0 (largest).var callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
}
};
apiInstance.editPdfResize(inputFile, paperSize, callback);

With this, you can instantly set the printing parameters for any PDF document.

The API Key can be found at no cost and with no commitment on the Cloudmersive website. This will give you access to 800 monthly calls across our entire library of APIs.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet