protected void btnPDFgnrate_Click(object sender, EventArgs e) { string url = HttpContext.Current.Request.Url.AbsoluteUri; Bitmap bitmap = new Bitmap(CaptureWebPage(url)); Response.ContentType = "image/jpeg"; bitmap.Save(Response.OutputStream, ImageFormat.Jpeg); //const int bufferLength = 10000; //byte[] buffer = new Byte[bufferLength]; //int length = 0; //Response.OutputStream.Write(buffer, 0, length); bitmap.Dispose(); bitmap.Dispose(); Response.End(); } public System.Drawing.Bitmap CaptureWebPage(string URL) { // create a hidden web browser, which will navigate to the page System.Windows.Forms.WebBrowser web = new System.Windows.Forms.WebBrowser(); // we don't want scrollbars on our image web.ScrollBarsEnabled = false; // don't let any errors shine through web.ScriptErrorsSuppressed = true; // let's load up that page! web.Navigate(URL); // wait until the page is fully loaded while (web.ReadyState != WebBrowserReadyState.Complete) System.Windows.Forms.Application.DoEvents(); System.Threading.Thread.Sleep(1500); // allow time for page scripts to update // the appearance of the page // set the size of our web browser to be the same size as the page int width = web.Document.Body.ScrollRectangle.Width; int height = web.Document.Body.ScrollRectangle.Height; web.Width = width; web.Height = height; // a bitmap that we will draw to System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(width, height); // draw the web browser to the bitmap web.DrawToBitmap(bmp, new System.Drawing.Rectangle(0, 0, width, height)); return bmp; // return the bitmap for processing }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)