locked
How do i capture a web page as an image file? RRS feed

  • Question

  • User-188857316 posted
    Hello All, I am trying to render HTML output of a .aspx page into an image file. For example: If I have a web page named WebForm1.aspx, then I would like to capture the output as a .jpeg file. There exists a utility on located on sourceforge.net: IECapt - A Internet Explorer Web Page Rendering Capture Utility http://iecapt.sourceforge.net/ and, I would like for my code to be able to perform the same function as this utility, however, this utility is an .exe and I have to Shell out of my aspx code and open a new process to run it as follows: using System.Diagnostics; Process myProcess = new Process(); myProcess.EnableRaisingEvents = False ; myProcess.StartInfo.RedirectStandardOutput = False; myProcess.StartInfo.UseShellExecute = False; myProcess.StartInfo.WorkingDirectory = "C:\Inetpub\wwwroot\TXWB\Forms"; myProcess.StartInfo.FileName = "C:\Inetpub\wwwroot\TXWB\Forms\IECapt.exe"; myProcess.StartInfo.Arguments = _ "http://localhost/TXWB/Forms/39610Confirm.aspx?objPATNO=186031" + "c:\test.jpeg"; myProcess.Start(); myProcess.WaitForExit(); myProcess.Dispose(); The resulting output I get by running the above is an image file of the target .aspx page after it has rendered through the IE rendering engine. The problem is I just can't figure out how to accomplish this same task within the .net framework with existing .net assemblies. I tried using the System.Net.WebClient assembly and am able to fetch the target .aspx page in a string variable as follows: using System.Text; using System.Net; string imageString; string URLToLoad; URLToLoad = "http://localhost/TXWB/Forms/39610Confirm.aspx?objPATNO=186031"; ASCIIEncoding encASCIIEncoding = new ASCIIEncoding(); WebClient wbcWebClient = new WebClient(); imageString = encASCIIEncoding.GetString(wbcWebClient.DownloadData(URLToLoad)); The imageString variable contains the HMTL markup of the target page, however, I don't know how to render this HTML through the IE rendering engine to save it as an image file. I tried to covert the source code for the IECapt utility, but it uses the Active Template Library, and I don't know if it's possible to convert. Here is the source code: http://cvs.sourceforge.net/viewcvs.py/iecapt/IECapt/IECapt/IECapt.cpp If you have any input you could provide, I am greatful for your thoughts. Thank you so much for take the time to read and reply and I greatly appreciate any suggestions. Mar
    Monday, December 20, 2004 2:36 PM

All replies

  • User-1372641848 posted
    This code explains concept. it works on my localmachine, you will have to add code to delete file and proper error handling.<%@ Page Language="C#" %> <%@ import Namespace="System.Diagnostics" %> <script runat="server"> string url="http://www.google.com"; void Page_Load(object sender, EventArgs e) { if(Request.Params["weburl"] != null){ url = Request.Params["weburl"]; } string savepath = String.Format("C:\\IECapt\\{0}.png" , System.Guid.NewGuid()); System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo.FileName = "C:\\IECapt\\IECapt.exe"; process.StartInfo.Arguments = String.Format("\"{0}\" \"{1}\"",url,savepath); process.StartInfo.UseShellExecute = false; process.Start(); process.WaitForExit(); process.Dispose(); Response.Clear(); Response.ContentType = "image/png"; Response.WriteFile(savepath); Response.End(); } </script>
    Monday, January 3, 2005 9:19 PM
  • User-907579122 posted

    It sometimes very  slowly, How can I improve its speed?

    thanks       

    Friday, August 11, 2006 11:33 PM
  • User1689678569 posted

    THNQ

    THNX A LOT

    IT'S WORKING 5N FOR ME

    Thursday, June 25, 2009 2:57 AM