Click here to Skip to main content
15,886,664 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to convert a asp.net web page to image along with the user feed details and save to a folder.I have used below code but I am not getting user entered data in the image and it is showing in the browser only,I want to save it in a folder.Plz check and suggest me.

C#
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
    }
Posted
Updated 31-Mar-15 19:04pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900