jsPDF-AutoTable icon indicating copy to clipboard operation
jsPDF-AutoTable copied to clipboard

Saving to server

Open jdr430 opened this issue 11 years ago • 3 comments

 var doc = new jsPDF('p', 'pt');
        var res = doc.autoTableHtmlToJson(table, true);
        doc.autoTable(res.columns, res.data);
        var pdf =doc.output();
        console.log(pdf)
        var data = new FormData();
        data.append("data" , pdf);
        var xhr = new XMLHttpRequest();
        xhr.open( 'post', 'upload.php', true );
        xhr.send(data);

Works.

jdr430 avatar Apr 24 '15 09:04 jdr430

Sweet!

simonbengtsson avatar Apr 24 '15 11:04 simonbengtsson

when i use this method, the PDF file saved is corrupted and only 3Kb of size, but when i choose to download that same file with doc.save() i get a file with ~6Mb. this is the php file i'm using:

'<?php

if(!empty($_POST['data'])){
$data = $_POST['data'];
$fname = "certificado.pdf"; 
$file = fopen("certificado/" .$fname, 'w');
fwrite($file, $data);
fclose($file);

?>

any ideas?

bryann-and avatar Dec 14 '17 19:12 bryann-and

bryann-and

If your pdf design has any lines or graphics from jspdf like. doc.line(10,100,200,100) the pdf will get corrupted when trying to send it this way.

I have been looking for a solution as well with no luck. Hope someone can figure out a solution.

malanvanwyk avatar Feb 14 '18 10:02 malanvanwyk