HTML DOM string copy, Canvas element not redrawn

Go To


I want to add printing to my Javascript web application. The application is developed in GWT.

My method includes copying the current active view (Widget) to an iFrame and print the iFrame. This works perfectly fine, when using plain HTML. When I add a Canvas Element, the Canvas element is copied as expected but not redrawn. Is there something I am missing?

2012-04-04 16:56
by Friedrich


I don't think you can do it that way, however you could send the canvas as an image to be printed, using someting like the following (in jQuery):

var image = $('canvas').toDataURL("image/png");

Using image as the src for an image will display the contents of the canvas. Instead of adding a canvas element, add an image witht the same dimensions, and replace its src.

2012-04-04 17:00
by aurbano
You are correct, canvas data is not a dom like svg or vml, so simply copying the element tree will not capture the content - Colin Alworth 2012-04-04 21:35