I want to use some images in jsPdf. These images come from another domain (API). This is my code:
let img = new Image();
img.src = 'myUrl';
docPdf.addImage(img, 'JPEG', col, row, width, height, 'FAST');
But I receive this error:
Access to image at 'http://127.0.0.1:8000/some-url' from origin 'http://127.0.0.1:4000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
ERROR Error: Supplied Data is not a valid base64-String jsPDF.convertStringToImageData
at Object.x.convertStringToImageData (jspdf.min.js:50)
Then I add crossOrigin to my url but I also receive that error.
img.crossOrigin = 'anonymous';
or img.crossOrigin = 'Anonymous';
I also set cors settings in backend:
CORS_ORIGIN_ALLOW_ALL = True