Print a HTML5 canvas element

JavascriptWeb DevelopmentFront End Scripts

The following is the code snippet to display an HTML5 canvas element.

<a href = "javascript:print_voucher()">PRINT CANVAS</a>
function print_canvas()

Here canvas_voucher is ID of canvas element.To make this start functioning we need to convert the canvas into .png image URL and open it in a new browser window. Print dialog is triggered to let user print the page.

function print_canvasr(){
   var win1 =;
   win1.document.write("<br><img src = '"+canvas.toDataURL()+"'/>");
Published on 11-Apr-2018 13:57:06