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

Last post 06-25-2009 2:57 AM by pranu239. 3 replies.

Sort Posts:

  • How do i capture a web page as an image file?

    12-20-2004, 2:36 PM
    • Member
      20 point Member
    • kingpoop
    • Member since 10-17-2002, 12:57 PM
    • Seattle, WA.
    • Posts 6
    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
  • Re: How do i capture a web page as an image file?

    01-03-2005, 9:19 PM
    • Contributor
      4,629 point Contributor
    • Jigar
    • Member since 06-17-2002, 5:41 AM
    • Ridgewood, NJ
    • Posts 935
    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>
    Jigar Desai
    -----------------------
    Do not forget to "Mark as Answer" on the post that helped you.
  • Re: How do i capture a web page as an image file?

    08-11-2006, 11:33 PM
    • Member
      25 point Member
    • seandong
    • Member since 08-12-2006, 3:02 AM
    • Posts 5

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

    thanks       

  • Re: How do i capture a web page as an image file?

    06-25-2009, 2:57 AM
    • Member
      6 point Member
    • pranu239
    • Member since 05-28-2009, 6:47 AM
    • Posts 3

    THNQ

    THNX A LOT

    IT'S WORKING 5N FOR ME

Page 1 of 1 (4 items)