Printing the contents of the canvas tag

2019-07-04 14:30发布

问题:

I make an application canvas. I load more image (png, gif) in canvas. When I click print on my browser (opera), the contents of the canvas tag does not print. With other browsers (FF, IE, Chrome), there is no problem. Why?

回答1:

this answer from Capture HTML Canvas as gif/jpg/png/pdf? might be useful.

var canvas = document.getElementById("mycanvas");
var img    = canvas.toDataURL("image/png");

with the value in IMG you can write it out as a new Image like so:

document.write('<img src="'+img+'"/>');