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

html2pdf creates a blank PDF and somethings shows a security error 'The operation is insecure' on iOS 16.x.x

Open uzeehan opened this issue 3 years ago • 7 comments

Hi,

The html2pdf.js creates a Blank PDF or throws an error 'The operation is insecure' on new iOS 16.0.2.

Below is the html2pdf config:

function generatePDF(true) {
    return new Promise(function(resolve, reject) {

        var element = document.getElementById("main");
        
        var options = {
            filename: 'document.pdf',
            image: {
                type: 'jpeg',
                quality: 0.5
            },
            html2canvas: {
                scrollX: 0,
                scrollY: 0,
                scale: window.devicePixelRatio && window.devicePixelRatio > 1 ? 0.8 : 1
            },
            jsPDF: {
                unit: 'pt',
                format: 'a4',
                orientation: 'portrait'
            }
        };

        var pdf = html2pdf().set(options).from(element);

        pdf.outputPdf('datauristring').then(function(data) {
            // if (true)
            //     pdf.save();
            resolve({
                data: data.replace("data:application/pdf;filename=generated.pdf;base64,", ""),
                type: "data:application/pdf"
            });
        }).catch(function(e) {
            alert('catch: ' + e);
            reject();
        });
    });
}

html2pdf.js version: 0.10.1 https://cdnjs.cloudflare.com/ajax/libs/html2pdf.js/0.10.1/html2pdf.bundle.min.js

I have noticed, 'scale' property of 'html2canvas' creates the security error. However, the above code works in earlier version of iOS.

I wonder what am I missing out from the config?

Thanks

uzeehan avatar Oct 18 '22 22:10 uzeehan

Hi @eKoopmans, do you have any fix of the above issue?

uzeehan avatar Oct 20 '22 06:10 uzeehan

same issue here. version 0.10.1 seems unusable.

lithiumlab avatar Nov 05 '22 16:11 lithiumlab

same issue here. version 0.10.1 seems unusable.

did you find any solution of the problem?

uzeehan avatar Nov 07 '22 06:11 uzeehan

Still not working on iOS

henryavila avatar Sep 12 '23 21:09 henryavila

Reducing the quality solved the problem here.

henryavila avatar Sep 20 '23 19:09 henryavila

For me the fix for iOS was simply to change html2pdf to html3pdf. import html3pdf from 'html3pdf'; const worker = html3pdf() .set(opt) .from(element) .toPdf() .get('pdf') .save();

LuuHoangVu avatar Jan 26 '24 02:01 LuuHoangVu