How to convert a Website URL into a PDF file in Node.JS

Need to render a website into PDF form? We have a handy little API that will do just that. It takes just a short time to set up — let’s look at how.

We’ll use npm install to get the client installed.

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

This now opens up our API to be called with this function here:

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.ConvertWebApi();var input = new CloudmersiveConvertApiClient.UrlToPdfRequest(); // UrlToPdfRequest | URL to PDF request parametersvar callback = function(error, data, response) {if (error) {console.error(error);} else {console.log('API called successfully. Returned data: ' + data);}};apiInstance.convertWebUrlToPdf(input, callback);

Enter the URL of the target website and it will be downloaded, processed, and sent back as a PDF. How easy was that! All of our APIs are just as easy to use, and we have hundreds.

Image for post
Image for post

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