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