PDF.js Inserting Images

后端 未结 2 488
梦毁少年i
梦毁少年i 2020-12-21 17:02

I\'ve started using PDF.js, an excelent work, by the way.

But now I want to insert an image (from a canvas element) on the pdf page. Here\'s my code:



        
2条回答
  •  感动是毒
    2020-12-21 17:48

    If I understand your question correctly you want to use an instead of a with pdf.js.

    So here is my fix for this problem, insert the returned image in a canvas as normal, give the canvas a display: none;.

    Then use the .toDataURL() method of the canvas element to get a src for your img.

    var canvas = document.getElementById("myCanves");
    var img = document.getElementById("myImg");
    img.src = canvas.toDataURL();
    

    I hope this helps.

提交回复
热议问题