JSPDF - Use lots and lots of images

纵饮孤独 提交于 2019-12-11 10:31:00

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!