How to Linearize a PDF in JavaScript
Getting tired of those lengthy download times for large files? Us too. To cut down on your wait time and boost productivity, you can use the following API in JavaScript to linearize the contents of a PDF and optimize the file for streaming download. This simple process will enable you to view the document as it loads; once the download is complete, you may already be halfway through your related task.
Let’s start things off by installing the jQuery library:
bower install jquery
With the installation out of the way, we are ready to input the PDF file and call the function:
var form = new FormData();
form.append("inputFile", fileInput.files[0], "file");var settings = {
"url": "https://api.cloudmersive.com/convert/edit/pdf/optimize/linearize",
"method": "POST",
"timeout": 0,
"headers": {
"Content-Type": "multipart/form-data",
"Apikey": "YOUR-API-KEY-HERE"
},
"processData": false,
"mimeType": "multipart/form-data",
"contentType": false,
"data": form
};$.ajax(settings).done(function (response) {
console.log(response);
});
To retrieve your API key, visit the Cloudmersive website and register for a free account; this will provide 800 calls/month across our entire library of APIs.