Incomplete or corrupt PNG file
See original GitHub issueI’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");
Issue Analytics
- State:
- Created 8 years ago
- Comments:21
Top Results From Across the Web
jsPDF Incomplete or corrupt PNG file - Stack Overflow
This type of error occurs because the image has not finished loading when you send to jsPdf, use onLoad event to check the...
Read more >[Client-side HTML to PDF] Error : Incomplete or corrupt PNG file
When trying to generate a PDF file, using the Client-side HTML to PDF forge component, I keep recieving the Error message "Incomplete or...
Read more >[Solved]-JsPDF: Error (Incomplete or corrupt png file)-Reactjs
Coding example for the question JsPDF: Error (Incomplete or corrupt png file)-Reactjs.
Read more >Corrupt PNG file may cause heap overflow in the BlackBerry ...
Even though the PNG extension has been removed from the list of supported file types, the BlackBerry Attachment Service may automatically detect ...
Read more >T43098 Blender creates corrupt PNG-files
When I render out a PNG sequence out of Blender and try to import into After Effects or Premiere Pro, I always get...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This happens because the image has not finished loading when you send it to jsPDF. You can ensure your image has finished loading before adding it to the document like this:
var myImage = new Image();
.myImage .src = 'https://www.myserver.com/somepath/myImage.png';
.myImage .onload = function(){
.doc.addImage(myImage , 'png', 5, 5, 40, 10);
.doc.save('myPDF.pdf');
.};
.Hrannar
I’m getting this issue as well, using Base64 which is fully loaded. It’s not consistent either, some images cause it and some don’t