How To Download Div Content As Image Using Javascript
In this post i ll show two ways that will allow your users to save what they see in their browse.
How to download div content as image using javascript. The html2canvas javascript library allows to capture screenshots and convert html to image using html5 canvas. Create a javascript image object. The info div contains three paragraph elements and the musical note image all of which will be displayed within the container. This example implements the above approach. Asp net html5 div table.
Canvas is a powerful drawing technology for the web. Finally insert it to the document. Then set its attributes like src height width alt title etc. Instead you can just crop the part of the image that needs to be seen. On download button click will convert canvas to png image format you can set any image format.
Html5 canvas has a function named todataurl which allows to convert its contents to image. Just a bit of friendly advice you may want to crop your screenshot. Create an empty image instance using new image. This object can be used to represent an html image tag on the page. Here we are ready with our canvas now we just need to download it as image format.
This page explains how to use javascript to load images into the browser s cache. The following code demonstrates how to create a javascript image object. Looks like you took a screenshot of your entire screen then squished the image to conform with code project maximum image width standards. One of its biggest caveats is that it s not easy to save the canvas image data to your computer. The container div represents the container that will hold all of our dynamic content.
Here mudassar ahmed khan has explained how to convert export html div or table to image using html canvas in asp net using c and vb net. Here s the code for downloading.