简体   繁体   English

使用jsPDF将多个不同的图像添加到PDF

[英]Add multiple different images to PDF with jsPDF

I'm trying to add multiple different images to PDF with jsPDF framework but in the end it generates PDF file with two similar images however if I try to generate two different PDF files with each single image everything works fine.我正在尝试使用 jsPDF 框架将多个不同的图像添加到 PDF 但最终它会生成具有两个相似图像的 PDF 文件但是如果我尝试生成两个不同的 PDF 文件,则每个图像都可以正常工作。 Here is my html:这是我的 html:

<img id="img1" src="/img1.jpg">
<img id="img2" src="/img2.jpg">

Here is my JS:这是我的 JS:

var doc = new jsPDF("landscape");
const img1 = $('#img1').attr("src");
const img2 = $('#img2').attr("src");
doc.addImage(img1, "JPEG", 140, 15, 90, 90, 'SLOW');
doc.addImage(img2, "JPEG", 140, 110, 90, 90, 'SLOW');
doc.save("sample.pdf");

What am I doing wrong?我究竟做错了什么?

I should have had to give more attention to the documentation, there are alises in case you have to add multiple images, so the finale code should look like that:我应该更多地关注文档,有别名以防你必须添加多个图像,所以结局代码应该如下所示:

var doc = new jsPDF("landscape");
const img1 = $('#img1').attr("src");
const img2 = $('#img2').attr("src");
doc.addImage(img1, "JPEG", 140, 15, 90, 90, "alias1", 'SLOW');
doc.addImage(img2, "JPEG", 140, 110, 90, 90, "alias2", 'SLOW');
doc.save("sample.pdf");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM