HTML5 canvas, convert canvas to PDF with jspdf.js

前端 未结 5 727
陌清茗
陌清茗 2021-02-04 12:10

I am trying to convert HTML5 canvas to PDF in JavaScript but I get a black background PDF. I tried to change the background color but still get black. The following is code I am

5条回答
  •  花落未央
    2021-02-04 13:04

    One very simple solution is that you are saving the image as jpeg. Saving instead as png works fine for my application. Of note, Blizzard's response also includes the print as png, and also produces non-black fill for transparent layers in the canvas.

      var canvas = event.context.canvas;
      var data = canvas.toDataURL('image/png');
    

    instead of

      var canvas = event.context.canvas;
      var data = canvas.toDataURL('image/jpg');
    

提交回复
热议问题