Convert html to image without temporary files in C#

The easiest way is to use our award-winning product htmlsnapshot.

Here are some guidelines:

 1. Download it and install. 
 2. Try the VB demo to make sure it works. Click the button to convert the url into image. This can tell you that the component is correctly installed. 
 3.  You can try the C# or VB.Net demo included. Open it with VS2003 or VS2005, build and run.
 4.  Another choice: you create a brand new C# project, add referrence to the htmlsnap2.dll.  Note, htmlsnapshot is an ActiveX control. So ususally it needs to be registered in the system’s OLE registry before using. You don’t need to do this manually if you install the component with our setup. If you want to deploy your application on a new machine, remember to register htmlsnap2.dll. Or you can use the regfree technology

Back to the topic of this post, how could you convert html to image such as jpeg, gif, png, tiff etc without generating temporary file? The code snippet is as below:

snap = new  CHtmlSnapClass ()               
snap.Url(“www.google.com”, “*”)
byte[] data = (byte[])snap.GetImageBytes(“.jpg”);
//byte[] data = (byte[])snap.GetThumbImageBytes(“.jpg”, 100, 100, 1);
//MessageBox.Show(data.Length.ToString());
FileStream  fs = File.OpenWrite(@”c:1.jpg”);      
BinaryWriter br = new BinaryWriter(fs);
br.Write(data);
br.Close();
fs.Close();