尝试使用jsPDF添加图片时出现CORS错误

时间:2020-03-29 18:25:37

标签: javascript jspdf

当尝试使用jsPDF添加图像时,出现以下控制台错误:

Access to XMLHttpRequest at 'https://batemo.de/wp-content/uploads/pdf_logo.jpg' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
xhr @ jspdf.debug.js:11878
jsPDFAPI.loadFile @ jspdf.debug.js:11891
createDataURIFromElement @ jspdf.debug.js:7038
jsPDFAPI.addImage @ jspdf.debug.js:7562
batemoLogo.onload @ cell_finder.html:307
load (async)
(anonymous) @ cell_finder.html:306

我使用以下代码:

var batemoLogo = new Image();
        batemoLogo.src = 'https://batemo.de/wp-content/uploads/pdf_logo.jpg';
        batemoLogo.onload = function() {
        doc.addImage(batemoLogo, 5, 5, 180, 160);};
        var imgWidth = doc.internal.pageSize.getWidth()*0.9;
        imgX = doc.internal.pageSize.getWidth()*0.1/2;
        doc.addImage(ScatterChart.getChart().getImageURI(), imgX, 100, imgWidth, 300);

该如何解决?

0 个答案:

没有答案