SOLUTION :
I tried to send pdf data as binary. I just base64 encode the string, send it and decode that in php.
JS:
var pdf = btoa(doc.output()); $.ajax({ method: "POST", url: "inc/test.php", data: {data: pdf}, }).done(function(data){ console.log(data); });
PHP:
if(!empty($_POST['data'])){ $data = base64_decode($_POST['data']); // print_r($data); file_put_contents( "../tmp/test.pdf", $data ); } else { echo "No Data Sent"; } exit();
source share