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

javascript - How to add Image in jspdf? - Stack Overflow

programmeradmin4浏览0评论

I have tried this code for add a image,but here Image has been not adding with pdf.

  function RunCode() {
       var imgData = 'data:pubali.jpg/jpeg;';
       var doc = new jsPDF();
       doc.setFontSize(10);
       doc.text(20, 20, 'Hello world!');
       doc.text(20, 30, 'This is client-side Javascript, pumping out a PDF.');
       doc.addImage(imgData, 'JPEG', 15, 40, 180, 160);
       doc.output('datauri');
     }

How can I add image with jspdf.

I have tried this code for add a image,but here Image has been not adding with pdf.

  function RunCode() {
       var imgData = 'data:pubali.jpg/jpeg;';
       var doc = new jsPDF();
       doc.setFontSize(10);
       doc.text(20, 20, 'Hello world!');
       doc.text(20, 30, 'This is client-side Javascript, pumping out a PDF.');
       doc.addImage(imgData, 'JPEG', 15, 40, 180, 160);
       doc.output('datauri');
     }

How can I add image with jspdf.

Share Improve this question asked Jun 3, 2014 at 5:40 Alimon KarimAlimon Karim 4,46910 gold badges46 silver badges70 bronze badges 1
  • imgdData shuld string containing base64 encoded jpg/jpeg image file – Matko Commented Sep 3, 2015 at 11:20
Add a ment  | 

2 Answers 2

Reset to default 3
  1. You Will make your image into a Data url.
  2. Go to this link http://dopiaza/tools/datauri/index.php for convert your image into a url.
  3. Then follow this link http://mrrio.github.io/jsPDF/ add your data url like this.

problem is you are not find out datauri,

 [1] : [http://dopiaza/tools/datauri/index.php] 

click this link upload your image.find out your datauri.

发布评论

评论列表(0)

  1. 暂无评论