问题
In JSPDF, my goal is to create a document that can vary from 1 to 1000 pages. Moreover, there are about 10-30 images on each page.
I am using the basic syntax:
var doc, exampleImg;
exampleImage = '64x64ConvertedDataURL';
doc = new jsPDF();
doc.addImage(exampleImg, 'PNG', 40, 20, 5, 5);
With this syntax, it goes without saying that it crashes and burns if it's longer than 100 pages. With no images, it can do the 1000 pages in under a second.
The dataURLs are converted 64x64 images. There are only about 4 different images, but they get repeated a lot of times.
Is there a more efficient way to do this?
回答1:
Well, this is a pretty hacky solution, but it works.
If looping, you can use setTimeout / setInterval and time it out before you actually go ahead and print the images to the PDF. It now works flawlessly... except that there's a couple seconds more of load time for the larger PDFs.
I used setTimeout(10) just to be extra safe.
来源:https://stackoverflow.com/questions/33698732/jspdf-use-lots-and-lots-of-images