html2pdf.js icon indicating copy to clipboard operation
html2pdf.js copied to clipboard

How to save pdf file on server?

Open stafra00 opened this issue 5 years ago • 4 comments

How can the output pdf file be saved on the server using script?

stafra00 avatar Jun 23 '20 09:06 stafra00

I have the same need

STouKi avatar Sep 09 '20 13:09 STouKi

I'm looking for that, too

smartwei avatar May 14 '21 03:05 smartwei

I found a way to get base64 data. The code is as follows:

var element = document.getElementById('zPrintDiv');
        var worker = html2pdf(element).toPdf();;
        worker = worker.output("datauristring").then(function (pdf) {
            console.log("conve pdf ok:")
            console.log(pdf);//this is base64 Data
        });

smartwei avatar May 14 '21 05:05 smartwei

I found a way to get base64 data. The code is as follows:

var element = document.getElementById('zPrintDiv');
        var worker = html2pdf(element).toPdf();;
        worker = worker.output("datauristring").then(function (pdf) {
            console.log("conve pdf ok:")
            console.log(pdf);//this is base64 Data
        });

Using the above method generates a double of the first page when I convert the base64 into pdf using the following code in Firefox:

$base_to_php = explode(',', $baseFromJavascript);

$data = base64_decode($base_to_php[1]);

header('Content-Type: application/pdf');

echo $data;

Is there any way around this?

seularts avatar Nov 01 '24 09:11 seularts