Skip to content

Incomplete or corrupt PNG file #662

@thilino

Description

@thilino

I'm trying to add an image to my PDF document but get this error Uncaught Error: Incomplete or corrupt PNG file in this line doc.addImage(imgData, 'PNG', 15, 40, 180, 160); , this happens when I add imgData var to my PDF file but not when i add imgPDF var for test.

Any idea cuz this happens

        var zip = new JSZip();
        var img = zip.folder("documets").folder("products");
        var row = "txtRow";

        var imgData = value['data'];
        var imgPDF = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAADCAIAAAA7ljmRAAAAGElEQVQIW2P4DwcMDAxAfBvMAhEQMYgcACEHG8ELxtbPAAAAAElFTkSuQmCC';

        var doc = new jsPDF('landscape');

        doc.text(20, 20, 'This is the default font.');
        doc.addImage(imgData, 'PNG', 15, 40, 180, 160);

        var pdf = doc.output();

        imgData = imgData.replace(/^data:image\/(png|jpg);base64,/, '');
        img.file("file.png", imgData, {base64: true});
        img.file("file.pdf", pdf,{binary: true});



    zip.file("products.csv", row);
    var content = zip.generate({type:"blob"});
    //FileSaver.js
    saveAs(content, "csv.zip");

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions