所以我有一个jspdf脚本正在使用。 .save可以正常工作,并输出图像+文本元素。
但是
doc.output()=仅文本
doc.output('datauristring')=损坏的pdf
我认为我缺少一些东西 这是我的代码示例
admin
答案 0 :(得分:0)
已解决,希望对所有人有帮助。
.output()正确发送了所有日期,而base64却被损坏了。所以我让php处理datauri,并在其上使用了base64_decode()。 然后将其保存到文件中。
完全解决了问题。
var pdf = doc.output('datauri');
var data = new FormData();
data.append("data" , pdf);
data.append("id" , id);
$.ajax({
url: 'upload.php',
data: data,
dataType: 'text',
processData: false,
contentType: false,
type: 'POST',
success: function (response) {
console.log('Exit to send request');
},
error: function (jqXHR) {
console.log('Failure to send request');
}
});
<?php
if(!empty($_POST['data'])){
$data = str_replace(' ','+',$_POST['data']);
$data = substr($imgData,strpos($imgData,",")+1);
$data = base64_decode($imgData);
$id = $_POST['id'];
$fname = "test.pdf"; // name the file
$file = fopen("api/warranty/pdf/" .$id, 'w'); // open the file path
fwrite($file, $data); //save data
fclose($file);
} else {
echo "No Data Sent";
}