Pramod M

Pramod M

  • NA
  • 81
  • 9.1k

Download HTML Content as PDF

Aug 26 2019 8:03 AM
function NoDueCertificatePDFDownload(value) {
var pdfdoc = new jsPDF('l', 'pt', 'a4');
var specialElementHandlers = {
'#ignoreContent': function (element, renderer) {
return true;
}
};
printHtmlToPdf(document.getElementById(value).innerHTML);
localStorage.setItem('load', 'false');
}
function printHtmlToPdf(html) {
localStorage.setItem('load', 'true');
var endpoint = 'https://v2018.api2pdf.com/chrome/html';
var apikey = '8ac65d3a-f0fe-4e1b-9a6b-d28de90b';
var payload = {
"html": html,
"inlinePdf": false
};
$.ajax({
url: endpoint,
method: "POST",
dataType: "json",
crossDomain: true,
contentType: "application/json; charset=utf-8",
data: JSON.stringify(payload),
cache: false,
beforeSend: function (xhr) {
/* Authorization header */
xhr.setRequestHeader("Authorization", apikey);
},
success: function (data) {
//console.log(data.pdf); //this is the url to the pdf, do something with it
window.location = data.pdf;
},
error: function (jqXHR, textStatus, errorThrown) {
}
});
}
 
 Without apikey need to download HTML as PDF Download.
 
 
 

Answers (3)