如何把pdf文件放到服务器,将生成的PDF文件存储在服务器上

小编典典

我设法使用来解决此问题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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值