Using the jsPDF plugin, I am creating a .pdf file and generating a download based on a button click. I would like to save the file onto my server i
If your PDF contains binary data, you can get into problems if you try to transfer the PDF via string. I used the blob output format of jsPDF with success.
var doc = new jsPDF();
// ... generate pdf here ...
// output as blob
var pdf = doc.output('blob');
var data = new FormData();
data.append('data' , pdf);
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (this.readyState == 4) {
if (this.status !== 200) {
// handle error
}
}
}
xhr.open('POST', 'upload.php', true);
xhr.send(data);
Your upload.php can then use the $_FILES array in PHP