Is it possible to capture or print what's displayed in an html canvas as an image or pdf?
I'd like to generate an image via canvas, and be able to generate a png from that image.
Is it possible to capture or print what's displayed in an html canvas as an image or pdf?
I'd like to generate an image via canvas, and be able to generate a png from that image.
You can use jspdf to capture a canvas into an image or pdf like this:
More info: https://github.com/MrRio/jsPDF
HTML5 provides Canvas.toDataURL(mimetype) which is implemented in Opera, Firefox, and Safari 4 beta. There are a number of security restrictions, however (mostly to do with drawing content from another origin onto the canvas).
So you don't need an additional library.
e.g.
Theoretically this should create and then navigate to an image with a green square in the middle of it, but I haven't tested.
Here is some help if you do the download through a server (this way you can name/convert/post-process/etc your file):
-Post data using
toDataURL
-Set the headers
-create image
-export image as JPEG
-or as transparent PNG