我是这里的新手,并且使用javascript和php。
我无法将jsPDF的PDF保存到服务器上的本地存储(自动生成)。在过去的作品中,但现在我只是将Canvas(javascript)放入HTML中,这是行不通的。
欢迎任何帮助:)
它与doc.save javascript一起使用,但不会自动保存到本地。
Javascript:
let doc = new jsPDF('p', 'pt', 'a4');
doc.addHTML(document.body, function () {
//this works but not store in local automatically
// doc.save('test.pdf');
//store to local storage
var pdf = btoa(doc.output());
$.ajax({
method: "POST",
url: "pdftoserver.php",
data: {data: pdf},
}).done(function(data){
console.log(data);
});
});
}
PHP:
<?php
session_start();
$pdfpath=$_SESSION['pdfpath']; //heredated, only path and name for pdf (with date...)
if(!empty($_POST['data'])){
$data = base64_decode($_POST['data']);
// print_r($data);
file_put_contents($pdfpath, $data );
} else {
echo "PDF failed";
}
exit();
?>
我的HTML头脚本:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.0.272/jspdf.debug.js"></script>
<script src="canvas.js"></script> <!--for paint and sign on html-->