How to Convert HTML String to PDF using JavaScript
Both HTML and URLs can be used to quickly render and screenshot a webpage. Our HTML to PDF API let’s you complete that process in an instant, and it then creates a new PDF document automatically with the screenshot it took. If you’re looking to streamline your web-screenshot documentation process, we’ve got you covered — take advantage of this API with the ready-to-run code provided below to structure your API call in JavaScript.
First things first — let’s start installing jQuery. Run the below command:
bower install jquery
After that, you’re only a few short steps away — just include the below code examples, copy in your API key (attainable by registering a free account on our website) where indicated in the documentation, and customize any request parameters as you see fit:
var settings = {
"url": "https://api.cloudmersive.com/convert/web/html/to/pdf",
"method": "POST",
"timeout": 0,
"headers": {
"Content-Type": "application/x-www-form-urlencoded",
"Apikey": "YOUR-API-KEY-HERE"
},
"data": {
"Html": "<string>",
"ExtraLoadingWait": "<integer>",
"IncludeBackgroundGraphics": "<boolean>",
"ScaleFactor": "<integer>"
}
};$.ajax(settings).done(function (response) {
console.log(response);
});