I'm trying to screenshot an invoice page in html as canvas with HTML2CANVAS, then create a pdf with pdfmake, I need to send the pdf file to the backend via http post, I have this function :
$scope.createPdf = function () {
html2canvas(document.getElementById('exportthis')).then(canvas => {
var data = canvas.toDataURL();
var docDefinition = {
content: [{
image: data,
width: 500,
}]
};
var file = pdfMake.createPdf(docDefinition)
var Fileblob = file.getBlob((Blob) => {
Blob.lastModifiedDate = new Date();
Blob.name = "Invoice.pdf;"
console.log(Blob);
var fd = new FormData();
fd.append('file', Blob, 'Invoice.pdf');
$http.post("/Home/SendInvoice", {data: fd})
.then(function successCallback(data) { },
function errorCallback(response) {
console.log(response.statusText);
})
.finally(function () {
}
);
});
});
};
I tried FormData and sending the Blob alone but it shows null in the backend.
public JsonResult SendInvoice(HttpPostedFileBase Attachement)
{
//Send Email with the file as an attachement
*
*
return Json("Email Sent", JsonRequestBehavior.AllowGet); ;
}