Add image in pdf using jspdf

前端 未结 12 695
离开以前
离开以前 2020-12-05 06:49

I am using jspdf to convert an image into a PDF.

I have converted the image into a URI using base64encode. But the problem is that there are no errors or warnings sh

12条回答
  •  执笔经年
    2020-12-05 07:33

    No need to add any extra base64 library. Simple 5 line solution -

    var img = new Image();
    img.src = path.resolve('sample.jpg');
    
    var doc = new jsPDF('p', 'mm', 'a3');  // optional parameters
    doc.addImage(img, 'JPEG', 1, 2);
    doc.save("new.pdf");
    

提交回复
热议问题