小编典典
我设法使用来解决此问题FormData(),方法如下:
$(document).on("click", "#PDF", function () {
var table = document.getElementById("result");
var cols = [],
data = [];
function html() {
var doc = new jsPDF('p', 'pt');
var res = doc.autoTableHtmlToJson(table, true);
doc.autoTable(res.columns, res.data);
var pdf =doc.output(); //returns raw body of resulting PDF returned as a string as per the plugin documentation.
var data = new FormData();
data.append("data" , pdf);
var xhr = new XMLHttpRequest();
xhr.open( 'post', 'upload.php', true ); //Post to php Script to save to server
xhr.send(data);
}
html();
});
upload.php
if(!empty($_POST['data'])){
$data = $_POST['data'];
$fname = "test.pdf"; // name the file
$file = fopen("testa/pdf/" .$fname, 'w'); // open the file path
fwrite($file, $data); //save data
fclose($file);
} else {
echo "No Data Sent";
}
关键部分是var pdf =doc.output();您要获取原始pdf数据的位置。
2020-07-26