How to Convert Standard HTML to PNG in JavaScript

Cloudmersive
1 min readAug 3, 2021

--

Have HTML that you need to convert to an image? If so, the PNG image format is a great choice, due to its versatility and quality. However, before you begin the extensive and tedious manual process, let me introduce you to an automated and simple solution. The following API can be used in JavaScript to instantly convert standard HTML (with full support for CSS, images, and other complex behavior) to an array of PNG images, saving you a lot of extra work.

Our first step is to run this command to install jQuery:

bower install jquery

Once the installation s complete, we can call the function:

var form = new FormData();
form.append("inputFile", fileInput.files[0], "file");
var settings = {
"url": "https://api.cloudmersive.com/convert/html/to/png",
"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);
});

And that’s it! Process complete and PNG delivered.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet