I heard from many colleagues something like: Can be HTML output rendered as image, and obtained image will look like HTML presentation in web browser? There are many web sites that do this like http://www.webshotspro.com/. But another solution and probably best is to use System.Windows.Forms.WebBrowser that internally uses IE Browser Engine.
The following sample code demonstrates how to use IE Browser Engine in console application to obtain web site screenshots.
[code:c#]
using System;
using System.Collections.Generic;
using System.Text;
//
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Imaging;
using System.Diagnostics;
using System.Drawing.Drawing2D;
namespace WebScreenShot
{
class Program
{
// Important IE Web Browser ActiveX can't run in Multi Threaded Apartment(MTA),
// in ASP.NET page set AspCompat attribute to True.
[STAThread]
static void Main(string[] args)
{
string url;
int with, height, s_width, s_height;
string fileName = string.Format(@"d:\webscreenshot_{0}.bmp", DateTime.Now.Ticks);
Console.Write("Enter URL:");
url = Console.ReadLine();
Console.Write("Enter Width:");
with = Convert.ToInt32(Console.ReadLine().Trim());
Console.Write("Enter Height:");
height = Convert.ToInt32(Console.ReadLine().Trim());
Console.Write("Enter Screen Width:");
s_width = Convert.ToInt32(Console.ReadLine().Trim());
Console.Write("Enter Screen Height:");
s_height = Convert.ToInt32(Console.ReadLine().Trim());
using (WebBrowser wb = new WebBrowser())
{
wb.Width = s_width;
wb.Height = s_height;
wb.ScrollBarsEnabled = false;
wb.Navigate(url);
while (wb.ReadyState != WebBrowserReadyState.Complete)
{
Application.DoEvents();
}
using (Bitmap bmpScreen = new Bitmap(s_width, s_height))
{
// DrawToBitmap is not supported but stil works :)
wb.DrawToBitmap(bmpScreen, new Rectangle(0, 0, s_width, s_height));
using (Bitmap bmp = new Bitmap(with, height, bmpScreen.PixelFormat))
{
using (Graphics g = Graphics.FromImage(bmp))
{
g.CompositingQuality = CompositingQuality.HighQuality;
g.SmoothingMode = SmoothingMode.AntiAlias;
g.InterpolationMode = InterpolationMode.HighQualityBilinear;
g.DrawImage(bmpScreen, new Rectangle(0, 0, with, height));
bmp.Save(fileName, ImageFormat.Bmp /*bmp for quality*/);
}
}
}
}
Process.Start(fileName);
Console.ReadKey();
}
}
}
[/code]
Note: code requires to add reference to System.Windows.Forms.dll & System.Drawing.dll assemblies.
Example screenshot: