我正在使用jsPDF生成电子课程的结业证书。我们的证书可以在Chrome,FF和Edge中正常运行,但是IE11不会生成PDF。 jspdf.debug.js(v1.4.1)正在抛出: “ addImage不支持“ UNKNOWN”类型的文件。
这是我们的脚本:
function createCert() {
// This is the function that will generate a PDF from an image and text fields.
var imgBackground = new Image();
imgBackground.src = "Opioid_1.jpg";
imgBackground.onload = function () {
var doc = new jsPDF({
orientation: 'landscape',
unit: 'in',
format: [11, 8.5]
});
doc.addImage(imgBackground, "JPEG", 0.2, 0, 10.5, 8.1);
// dummy data
var userName = "John Smith";
var fileName = "CertPDF.pdf";
var courseTitle = "Basics 101";
var dateCompleted = "09/10/2010";
doc.setFontSize(12);
doc.setTextColor(0, 0, 0);
doc.setFont("helvetica");
doc.setFontType("bold");
doc.text(4.6, 6.0, userName, null, null, 'left');
doc.setFontType("normal");
doc.text(.46, 3.6, dateCompleted, null, null, 'left');
doc.text(.46, 1.9, courseTitle, null, null, 'left');
doc.text(.46, 4.4, userName, null, null, 'left');
doc.save(fileName);
};
}