I am able to add a jpg image to a pdf document using insert image but for some reason the code throws an error when I try to add a png image. Why would this be failing? This is the error that I see getting thrown
The code I am using is fairly basic from the examples I have found online.
img.onload = function() {
var width = pdfdoc.internal.pageSize.width;
var ratio = width / this.naturalWidth;
var height = this.naturalHeight * ratio;
var padding = 15;//jQuery("#docpadding").val();
var yPadding = 25;
pdfdoc.addImage(this, "PNG", padding, yPadding, width - (padding*2), height);
}
1 Answer
Have you enabled png support through the libraries? If you check the latest code in the github repo, you will see there is a png_support.js file in the repo https://github.com/MrRio/jsPDF/tree/master/src/modules . You need to include this script as part of your project if you want to support PNG files.
You will also need to include png.js and zlib.js from https://github.com/MrRio/jsPDF/tree/master/src/libs if you want the png support to work without errors.
Related Questions
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically
[Centos] Delete All Files And Folders That Contain a String