0
votes

I'm trying to add images to my jsPDF but they all turn out scrambled, here's an example: example

Text and shapes work just fine. I've tried many pngs and jpegs, in many formats but they all turn out similar. I use the same code as the one on the jsPDF main site: var imgData = 'data:image/jpeg;base64,...' var doc = new jsPDF()

doc.text(35, 25, 'HELLO')
doc.addImage(imgData, 'JPEG', 15, 40, 180, 160)

After creating the pdf i save it using the Cordova filesystem. What could be the issue here?

Thanks in advance

1
stackoverflow.com/a/11900836/7707749 this answer might help you out. - King Reload
What is the original image size? from what I know, jsPDF won't compress your image, instead it will crop a portion that will fit your coordinates. - Dinca Adrian
I don't think that's the issue here, the image is 180x160 like specified in the method so it's not being cropped. I've tried online base64 strings too without specifying image size and they give similar results. - Marre

1 Answers

0
votes

I found my solution here

My writer was producing corrupt PDFs when images were added, this can be resolved by making use of an ArrayBuffer.