简体   繁体   中英

save PDF from html2canvas on server

I would like to ask about how I can save the generated PDF file (via htm2pdf) on a remote server? I know how to save a file, but I do not know how to "pass" it to to the BTOA function which will allow me to upload file; for example:

  var pdff = new html2pdf()
    .set({ html2canvas: { scale: 3 } })
    .from(element)
    .save(); //works, allows to download the correct file
    var pdf = btoa(pdff.output()); // I know, wrong syntax, how to write it correctly?
    $.ajax({
      method: "POST",
      url: "upload.php?nazwa=" + nazwa,
      data: {data: pdf},
    }).done(function(data){             
       console.log(data);
    });

Okay, I figured it out! script below allows you to simultaneously download the file and simultaneously save it on the server :)

var pdff = new html2pdf()
    .set({ html2canvas: { scale: 3 } })
    .from(element)
    .save()
    .outputPdf().then(function(pdf) {
        var fi = btoa(pdf); 
        $.ajax({
            method: "POST",
            url: "upload.php?nazwa=file.pdf",
            data: {data: fi},
        }).done(function(data){
            console.log(data);
        }); 
    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM