My JSP page contains two buttons labeled "download" and "sendemail". When the "Sendmail" button is clicked, an ajax method is triggered to generate a PDF version of the HTML body and send it to the back-end controller.
I attempted to utilize the following code snippet:
document.getElementById('reportbuttons').remove();
prior to:
doc.addHTML(document.body, function() {....
The 'reportbuttons' represents the ID of the div tag housing the "sendmail" and "download" buttons. However, both buttons disappear once the "sendmail" button is clicked.
function sendMail() {
let doc = new jsPDF('p','pt','a4');
doc.setProperties({
title: ' Report PDF Document',
subject: 'subject',
author: 'XYZ',
keywords: 'generated, javascript, web 2.0, ajax',
creator: 'ABC '
});
doc.addHTML(document.body, function() {
var data = doc.output('datauristring');
console.log(data);
var reqJson = {};
reqJson.machineId = "<%=machineId%>";
reqJson.monthYear = "<%=monthYear%>";
reqJson.data = data;
console.log();
$.ajax(
{
url : "sendMail/",
type: "POST",
dataType: 'json',
data : JSON.stringify(reqJson),
contentType: "application/json",
success:function(data)
{
alert('mail sent successfully');
console.log(data);
},
error: function(data)
{
}
});
});
}
I aim to exclude these two buttons from the generated PDF while retaining them on the JSP webpage.