Monday, 9 September 2013

Issue when saving the webpage as image in asp.net c# web application

Issue when saving the webpage as image in asp.net c# web application

I am facing an issue regarding saving the whole webpage as image. i have a
web application and all the controls used are 'user controls'. i have one
page in my application and using that i grab the webpage image and saving
to one folder in the solution. i got the image but the issue is the height
of the image is not correct . ie the page height that i am receiving is
not correct.. when i debug , it shows 0px as height for the page .
my code is as follows...
protected void GetThumbnailWorker()
{
using (WebBrowser browser = new WebBrowser())
{
//browser.ClientSize = new Size(_width, _height);
//browser.ClientSize = new Size(960,2000);
browser.ScrollBarsEnabled = false;
browser.ScriptErrorsSuppressed = true;
browser.Navigate(_url);
// Wait for control to load page
while (browser.ReadyState != WebBrowserReadyState.Complete)
Application.DoEvents();
// Render browser content to bitmap
int imgaewidth = 0;
int imageheight=0;
imgaewidth=browser.Document.Body.ScrollRectangle.Width;
imageheight=browser.Document.Body.ScrollRectangle.Height;
if (imageheight <100)
{
imageheight = 1500;
}
if (imgaewidth == 0)
{
imgaewidth = 964;
}
browser.ClientSize = new Size(imgaewidth, imageheight);
_bmp = new Bitmap(imgaewidth, imageheight);
browser.DrawToBitmap(_bmp, new Rectangle(0, 0,
imgaewidth, imageheight));
}
}
can any one help me...?

No comments:

Post a Comment