converting HTML into an image in asp.net applicationhttp://forums.asp.net/t/1649909.aspx/1?converting+HTML+into+an+image+in+asp+net+applicationFri, 04 Feb 2011 20:59:57 -050016499094288338http://forums.asp.net/p/1649909/4288338.aspx/1?converting+HTML+into+an+image+in+asp+net+applicationconverting HTML into an image in asp.net application <p>HI All,</p> <p>My require ment is such...</p> <p>1. in&nbsp;asp.net application,&nbsp; i will draw certain shapes (rectangle,elipse etc). using basic html such as table,td tr, &lt;p&gt; etc. ..so basicaly a html deigner in broswer on client side.</p> <p>2. i will also type some text in &lt;P&gt; tags ...</p> <p>3. will set fonts , style using using css.</p> <p>all this will happen in browser just like a basic html editor after that i will post asp.net page back to server. onserver side i want to convert the HTML view that i was seeing in the browser into an image.</p> <p>a)can some one please suggest how to do this in .net .40 or 3.0 ?</p> <p>b)are there any third part components that can do this. are these third party&nbsp;components multithreaded and scalable?</p> <p>here is one ...that seem to do it ..not used it yet..</p> <p><a href="http://www.acasystems.com/en/web-thumb-activex/faq-convert-html-to-image-in-asp.net.htm">http://www.acasystems.com/en/web-thumb-activex/faq-convert-html-to-image-in-asp.net.htm</a></p> <p>&nbsp;</p> 2011-02-04T18:19:34-05:004288362http://forums.asp.net/p/1649909/4288362.aspx/1?Re+converting+HTML+into+an+image+in+asp+net+applicationRe: converting HTML into an image in asp.net application <p>Hi,</p> <p>You can see code snippet along with explaination here</p> <p><br> </p> <p><br> </p> <h2><a href="http://pietschsoft.com/post/2008/07/23/C-Generate-WebPage-Thumbmail-Screenshot-Image.aspx" class="title">C#: Generate WebPage Thumbmail Screenshot Image</a></h2> &lt;div class=&quot;info&quot;&gt; <span class="date">23. July 2008 <br> </span> <h1 id="title"><a href="http://pietschsoft.com/">Chris Pietschmann</a></h1> &lt;div class=&quot;act&quot;&gt; <span class="comments"><a rel="nofollow" href="http://pietschsoft.com/post/2008/07/23/C-Generate-WebPage-Thumbmail-Screenshot-Image.aspx#comment">Comments (18)</a></span> &lt;div class=&quot;fixed&quot;&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class=&quot;fixed&quot;&gt; &lt;/div&gt; &lt;/div&gt; <p>There are a few services out there that serve up screenshots of any webpage for you to display on your website. One popular one is <a href="http://kwiboo.com/">Kwiboo</a>; this is the one that <a href="http://dotnetkicks.com/"> DotNetKicks </a>uses. For some time now I've wondered what the easiest way to do this in .NET was, and today I stumbled upon the undocumented WebBrowser.DrawToBitmap method that makes this extremely easy to do.</p> <p>By the way, I stumbled upon the WebBrowser.DrawToBitmap while taking a look at the source code for the <a href="http://smallsharptools.com/Projects/WebPreview/">WebPreview tool over at SmallSharpTools.com</a>.</p> <p>Here's a sample method that returns a Bitmap representation of a webpage:</p> <pre class="csharpcode"><span class="kwrd">public</span> Bitmap GenerateScreenshot(<span class="kwrd">string</span> url)<br>{<br> <span class="rem">// This method gets a screenshot of the webpage</span><br> <span class="rem">// rendered at its full size (height and width)</span><br> <span class="kwrd">return</span> GenerateScreenshot(url, -1, -1);<br>}<br><br><span class="kwrd">public</span> Bitmap GenerateScreenshot(<span class="kwrd">string</span> url, <span class="kwrd">int</span> width, <span class="kwrd">int</span> height)<br>{<br> <span class="rem">// Load the webpage into a WebBrowser control</span><br> WebBrowser wb = <span class="kwrd">new</span> WebBrowser();<br> wb.ScrollBarsEnabled = <span class="kwrd">false</span>;<br> wb.ScriptErrorsSuppressed = <span class="kwrd">true</span>;<br> wb.Navigate(url);<br> <span class="kwrd">while</span> (wb.ReadyState != WebBrowserReadyState.Complete) { Application.DoEvents(); }<br><br><br> <span class="rem">// Set the size of the WebBrowser control</span><br> wb.Width = width;<br> wb.Height = height;<br><br> <span class="kwrd">if</span> (width == -1)<br> {<br> <span class="rem">// Take Screenshot of the web pages full width</span><br> wb.Width = wb.Document.Body.ScrollRectangle.Width;<br> }<br><br> <span class="kwrd">if</span> (height == -1)<br> {<br> <span class="rem">// Take Screenshot of the web pages full height</span><br> wb.Height = wb.Document.Body.ScrollRectangle.Height;<br> }<br><br> <span class="rem">// Get a Bitmap representation of the webpage as it's rendered in the WebBrowser control</span><br> Bitmap bitmap = <span class="kwrd">new</span> Bitmap(wb.Width, wb.Height);<br> wb.DrawToBitmap(bitmap, <span class="kwrd">new</span> Rectangle(0, 0, wb.Width, wb.Height));<br> wb.Dispose();<br><br> <span class="kwrd">return</span> bitmap;<br>}</pre> &lt;div class=&quot;content&quot;&gt;<style type="text/css"> <!-- .csharpcode, .csharpcode pre {font-size:small; color:black; font-family:consolas,"Courier New",courier,monospace; background-color:rgb(255,255,255)} .csharpcode pre {margin:0em} .csharpcode .rem {color:rgb(0,128,0)} .csharpcode .kwrd {color:rgb(0,0,255)} .csharpcode .str {color:rgb(0,96,128)} .csharpcode .op {color:rgb(0,0,192)} .csharpcode .preproc {color:rgb(204,102,51)} .csharpcode .asp {background-color:rgb(255,255,0)} .csharpcode .html {color:rgb(128,0,0)} .csharpcode .attr {color:rgb(255,0,0)} .csharpcode .alt {background-color:rgb(244,244,244); width:100%; margin:0em} .csharpcode .lnum {color:rgb(96,96,96)} --> </style> <p>Here are some example usages of the above method:</p> <pre class="csharpcode"><span class="rem">// Generate thumbnail of a webpage at 1024x768 resolution</span><br>Bitmap thumbnail = GenerateScreenshot(<span class="str">&quot;http://pietschsoft.com&quot;</span>, 1024, 768);<br><br><span class="rem">// Generate thumbnail of a webpage at the webpage's full size (height and width)</span><br>thumbnail = GenerateScreenshot(<span class="str">&quot;http://pietschsoft.com&quot;</span>);<br><br><span class="rem">// Display Thumbnail in PictureBox control</span><br>pictureBox1.Image = thumbnail;<br><br><span class="rem">/*</span><br><span class="rem">// Save Thumbnail to a File</span><br><span class="rem">thumbnail.Save(&quot;thumbnail.png&quot;, System.Drawing.Imaging.ImageFormat.Png);</span><br><span class="rem">*/</span></pre> &lt;/div&gt; <p><br> </p> <p><span id="search" style="visibility:visible"><span class="tl"></p> <h3 class="r"><a href="http://www.google.co.in/url?sa=t&amp;source=web&amp;cd=9&amp;ved=0CGUQFjAI&amp;url=http%3A%2F%2Fstackoverflow.com%2Fquestions%2F3012728%2Fhow-to-convert-aspx-html-page-to-image-format&amp;rct=j&amp;q=convert%20html%20page%20to%20image%20asp.net&amp;ei=x1RMTZT0N4q3rAeZ-fXZBg&amp;usg=AFQjCNGNIicM70QnWsnxJXGUx64Yap9giw&amp;sig2=73TsKaUfajj-_550miWjQQ&amp;cad=rja" class="l"><i>asp</i>.<i>net</i> - How to <i>convert</i> *.aspx (<i>HTML</i>) <i>page to Image</i> format <b>...</b></a><br> </h3> <h3 class="r">Regards<br> </h3> </span></span> <p></p> 2011-02-04T18:39:01-05:004288502http://forums.asp.net/p/1649909/4288502.aspx/1?Re+converting+HTML+into+an+image+in+asp+net+applicationRe: converting HTML into an image in asp.net application <p>Thanks however what i m trying to do is&nbsp;some what different...</p> <p>i do not want to make request to a web page and convert the&nbsp;out put into image....instead i need to do following..</p> <p>belwo is the exact sequence...may be it was unclear in my earlier post..</p> <p>1. use will request may asp.net web page in browser.</p> <p>2. he will use the html editor on this page to create some html&nbsp;layout.</p> <p>3.he will hit 'save to image' button on this page. clicking on this button will do a post back to the server.</p> <p>4. now the server side in code behind,upon post back, &nbsp;i want to collect what was the&nbsp;view in&nbsp;browser before user hit &nbsp;&nbsp;'save to image' button and convert that view into image....</p> <p>is this possible...it is different than&nbsp;requesting a URL using a webrequest object and saving the stream to image.</p> <p>Thanks</p> <p>Siddharth</p> 2011-02-04T20:59:57-05:00