最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Add multiple different images to PDF with jsPDF - Stack Overflow

programmeradmin0浏览0评论

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. Here is my html:

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

Here is my 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'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. Here is my html:

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

Here is my 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?

Share Improve this question edited Dec 11, 2020 at 12:26 basilique asked Dec 11, 2020 at 12:19 basiliquebasilique 3033 silver badges9 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 7

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");
发布评论

评论列表(0)

  1. 暂无评论