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 instead of initiating the download. So when the button is clicked I would like the file to be saved in :
/tmp/uploads/pdf/example.pdf
I am aware I need have to use Jquery.Ajax
to post the file to the server. However, looking at the documentation and I didn't see any support for .pdf
as a datatype.
My code:
$(document).on("click", "#PDF", function () {
var table = document.getElementById("result");
var tbl = window.sessionStorage.getItem("tbl");
var cols = [],
data = [];
function html() {
var doc = new jsPDF('p', 'pt');
var res = doc.autoTableHtmlToJson(table, true);
doc.autoTable(res.columns, res.data);
doc.save( tbl+".pdf");
}
html();
});
Based on this xml document saving example I tried the following:
var pdfDocument = doc.save( tbl+".pdf");
var pdfRequest = $.ajax({
url: "/tmp/uploads/pdf",
processData: false,
data: pdfDocument
});
This downloaded the file instead of saving it. How can I save the file?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…