How to rasterize a PDF into an image-based PDF in Node.JS

Today I’m going to show you how to rasterize a PDF the easy way. So forget all of that tricky coding and format technicalities, because we won’t be needing them today. Instead we will be employing an API to simplify our lives immensely. Let’s look at the process involved.

We can add our client with this reference for package.json:

"dependencies": {
"cloudmersive-convert-api-client": "^2.1.6"
}

After the installation is complete, we will have access to our API functions, which means we can call editPdfRasterize, like so:

var CloudmersiveConvertApiClient = require('cloudmersive-convert-api-client');var defaultClient = CloudmersiveConvertApiClient.ApiClient.instance;// Configure API key authorization: Apikeyvar Apikey = defaultClient.authentications['Apikey'];Apikey.apiKey = 'YOUR API KEY';// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)//Apikey.apiKeyPrefix = 'Token';var apiInstance = new CloudmersiveConvertApiClient.EditPdfApi();var inputFile = "/path/to/file"; // 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.editPdfRasterize(inputFile, callback);

And just like that, we are already done with our task. Just input a text PDF and the API will return its rasterized form, simple as that.

Image for post
Image for post

Written by

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

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store