6

I'm doing complex html operations on images (drag & drop) and when I'm done, I need to take the screenshot of the page and get the taken image save it on server (virtual dir).

So what I need is

Image img = CaptureURL("www.a.com/b.aspx");

Does anyone know of a library that could help me do this?

Thank you

Pabuc
  • 5,500
  • 7
  • 35
  • 52
  • Would a PDF of the HTML generated help? If so, check this out: http://code.google.com/p/wkhtmltopdf/ – Icarus Sep 09 '11 at 13:31

1 Answers1

4

One solution is to use the WebBrowser control and render the result on a bitmap.

Here is the full solution, I think is simple and fast.

http://pietschsoft.com/post/2008/07/c-generate-webpage-thumbmail-screenshot-image.aspx

Other way is to use the IECapt that is a capture utility that can run on server and you can call it from your pages using the Process.Start.

here is the second solution.

http://codegod.org/WebAppCodeGod/Screenshot-of-Webpage-with-ASP-NET-AID398.aspx

And there is the javascript way, that your user render the page on the client side and send you the image. See some examples here : http://hertzen.com/experiments/jsfeedback/ and the source code is here: http://html2canvas.hertzen.com/

Hope this help

Aristos
  • 64,863
  • 15
  • 114
  • 148
  • There is no webbrowser in Web, that is for winforms I guess. I need a solution like your first one (which captures on server side). – Pabuc Sep 10 '11 at 20:35
  • webbrowser is located in this namespace: System.Windows.Forms but could be used in web based applications. – Wessam El Mahdy Mar 28 '17 at 22:08
  • I've been using this in the following way: an ashx handler which loads the image in a `WebBrowser `control, and then get's the bytes and writes it to the stream. However, each request like this results in a new AspNet session being generated. Do you know how I can forward the cookies that comes in on the ashx request, to the `WebBrowser `control? – hynsey Apr 09 '22 at 15:57
  • @hynsey the cookie exist on all page under the same domain. What is not is the session... read this answers and the comment's ! https://stackoverflow.com/questions/14181408/httpcontext-current-session-is-null-in-ashx-file/14181556#14181556 https://stackoverflow.com/questions/6703423/share-session-between-ashx-and-aspx/6705939#6705939 – Aristos Apr 09 '22 at 17:42
  • @Aristos - Thanks. I've already applied recommendations from both of those answers :) Still no joy. In the end I implemented an alternative solution which doesn't depend on WebBrowser. – hynsey Apr 11 '22 at 10:47