使用jsPDF将PDF保存到服务器是不可能的

I'm newbie here and with javascript & php.

I can't save my PDF's with jsPDF to local storage on server (automatically generated). In the past works, but now I just put Canvas (javascript) into my HTML, and it doesn't work.

Any help is welcome :)

It works with doc.save javascript, but is not saving automatically to local.

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();
?>

MY HTML head scripts:

<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-->
dousao6260
dousao6260 谢谢你的答复。在第一行我有一个功能。这个}关闭它。
大约 2 年之前 回复
doujiazong0322
doujiazong0322 看起来你在这里张贴的js的末尾有一个额外的}。这是一个错字吗?
大约 2 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐