How to Linearize a PDF in Node.JS

Cloudmersive
Nov 18, 2020

PDF files can often be heavy and take long amounts of time to download. You can optimize this process by linearizing your files. Using the following API, your PDF file will be simplified internally, with the contents stored in the correct order for viewing, allowing large files to be viewed while its contents continuously are downloaded.

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.editPdfLinearize(inputFile, callback);

With this, you can optimize your overall efficiency.

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.

--

--

Cloudmersive

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