提高dom-to-image lib的性能

问题描述 投票:0回答:1

我正在使用dom-to-image lib将DOM导出到我创建PDF文档的blob。

问题是功能完成需要大约25秒。

有没有任何已知的方法可以如何优化dom-to-image?

let map = document.getElementById('map');

domtoimage.toBlob(map).then(imageBlob => {
            ExportTools.exportService.getPDF(imageBlob, eventData);
        });

导出的图片宽度几乎是1920px,并且有很多空白区域。

reactjs image dom
1个回答
1
投票

根据我对dom-to-image的经验,XHR请求需要花费大量时间来应用字体。如果您使用的字体不是很重要,请尝试使用dom-to-image的分叉版本,看看它是否适合您。我可以将加载时间从15-20秒减少到2秒。我输出的图像也是1500px左右。

尝试在项目中包含这个分叉版本:https://github.com/venkat4541/dom-to-image

© www.soinside.com 2019 - 2024. All rights reserved.