How to Convert HTML to PNG Image Array with Node.js

Cloudmersive
2 min readDec 22, 2022

--

Saving documents in HTML format is a great way to make files viewable on a web browser, and once that’s done, creating PNG versions of those HTML files is an ideal way to document the freshly conceived web view. The below code will make HTML to PNG document conversions easy to perform at scale in any of your applications; just copy and paste the Node.js code examples provided below to structure your API call, and after that, authenticate our service with a free-tier Cloudmersive API key (you can get one by registering a free account on our website).

First things first, let’s install the SDK by running the command provided below:

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

Next up, let’s call the function, supplying our HTML document and free API key in their respective request fields:

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.ConvertDocumentApi();

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

Now you can simply call the function and reap the benefits of your new PNG documentation. It’s that easy!

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet