Charith Amila
Charith Amila

Reputation: 75

How Print html5 canvas with it parent div

My web page has a canvas inside div. i need to print this div with canvas using javascript . enter image description here

Upvotes: 0

Views: 1349

Answers (2)

reinerBa
reinerBa

Reputation: 1660

You can html2Canvas it gives you a png of the visible part of your Website. You can try it via browser console.

Upvotes: 0

David R
David R

Reputation: 15637

You need to convert your canvas to a normal image to achieve this.

Get the data URI containing a representation of the image using the canvas.toDataURL like this,

var canvasObj = document.getElementById("yourCanvasId");
var imgObj    = canvasObj.toDataURL("image/png");

Then you can write the image object as,

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

This will work fine while taking the printouts.

Hope this helps!.

Upvotes: 1

Related Questions