JSPDF-使用大量图像 [英] JSPDF - Use lots and lots of images

查看:78
本文介绍了JSPDF-使用大量图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在JSPDF中,我的目标是创建一个从1到1000页不等的文档.此外,每页上大约有10到30张图像.

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.

我正在使用基本语法:

var doc, exampleImg;
exampleImage = '64x64ConvertedDataURL';
doc = new jsPDF();
doc.addImage(exampleImg, 'PNG', 40, 20, 5, 5);

使用这种语法,不用说它超过100页时就会崩溃并烧毁.没有图像,它可以在一秒钟内完成1000页.

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.

dataURL被转换为64x64图像.大约只有4张不同的图像,但是它们会重复很多次.

The dataURLs are converted 64x64 images. There are only about 4 different images, but they get repeated a lot of times.

有没有更有效的方法?

推荐答案

嗯,这是一个非常hacky的解决方案,但是它可以工作.

Well, this is a pretty hacky solution, but it works.

如果循环播放,则可以使用setTimeout/setInterval对其进行超时,然后再实际进行操作并将图像打印到PDF.现在它可以完美地工作了……除了较大的PDF的加载时间增加了几秒钟.

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.

我使用setTimeout(10)只是为了更加安全.

I used setTimeout(10) just to be extra safe.

这篇关于JSPDF-使用大量图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆