Hi All Im having alot of trouble trying to post a PDF file generated via jsPDF using javascript. I use the pdf.output('datauristring') method to get the base64 of the PDF file but i cannot understand how to send this to the controller without getting an 'Illegal Invocation' Error in console.
function testPdfSend() {
let pdf = new jsPDF('p', 'pt', 'a3'); // a4: part of the page is cut off?
pdf.html(document.body, {
callback: function (pdf) {
var pdfContent = pdf.output('datauristring');
$.ajax({
url: "/Jobs/SendEmailTest",
type: 'POST',
contentType: 'application/json',
data: {data : JSON.stringify(pdfContent)}
});
}
});
}
Controller/Server side code:
public ActionResult SendEmailTest(string data)
{
//create pdf
var pdfBinary = Convert.FromBase64String(data);
return null;
}
UPDATE:
have tried using output('blob') method which I can see the controller method being hit however the data string is null.
function testPdfSend() {
var doc = new jsPDF("l", "pt", "letter");
var file = doc.output('blob');
var fd = new FormData(); // To carry on your data
fd.append('data',file);
$.ajax({
url: "/Jobs/SendEmailTest",
data: fd,
dataType: 'text',
processData: false,
contentType: false,
type: 'POST'
});
}
server method unchanged