1

I'm new to ASP.net. For my uni project I need to capture part of the web page (table). I tried few methods already available in but they don't provide what i want. for example

I used this code

using System.Drawing;
using System.Drawing.Imaging;
using System.Threading;
using System.Windows.Forms;

class Program
{
    [STAThread]
    static void Main()
    {
        int width = 1000;
        int height = 1000;

        using (WebBrowser browser = new WebBrowser())
        {
            browser.Width = width;
            browser.Height = height;
            browser.ScrollBarsEnabled = true;

            // This will be called when the page finishes loading
            browser.DocumentCompleted += Program.OnDocumentCompleted;

            browser.Navigate("http://www.aspsnippets.com/Articles/Print-specific-part-of-web-page-in-ASPNet.aspx");

            // This prevents the application from exiting until
            // Application.Exit is called
            Application.Run();
        }
    }

    static void OnDocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
        // Now that the page is loaded, save it to a bitmap
        WebBrowser browser = (WebBrowser)sender;

        using (Graphics graphics = browser.CreateGraphics())
        using (Bitmap bitmap = new Bitmap(browser.Width, browser.Height, graphics))
        {
            Rectangle bounds = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
            browser.DrawToBitmap(bitmap, bounds);
            bitmap.Save("screenshot.bmp", ImageFormat.Bmp);
        }

        // Instruct the application to exit
        Application.Exit();
    }
}

}

  • Accroding to my opinion you should create a html page which contains only that portion you want to capture, and you can generate image or pdf of that page. Ypu can find utility for url to image like itextsharp – ITGenius Jan 01 '17 at 10:31

0 Answers0