Exemple #1
0
        public void Start()
        {
            BrowserThread = new Thread(() =>
            {
                Browser = new WebBrowser();
                Browser.Width = Ballz.The().GraphicsDevice.Viewport.Width;
                Browser.Height = Ballz.The().GraphicsDevice.Viewport.Height;
                Browser.ScrollBarsEnabled = false;
                //Browser.IsWebBrowserContextMenuEnabled = false;
                LatestBitmap = new Bitmap(Browser.Width, Browser.Height);
                Browser.Validated += (s, e) =>
                {
                    lock (this)
                    {
                        Browser.DrawToBitmap(LatestBitmap, new Rectangle(0, 0, Browser.Width, Browser.Height));
                    }
                };

                Browser.DocumentCompleted += (s, e) =>
                {
                    lock (this)
                    {
                        Browser.DrawToBitmap(LatestBitmap, new Rectangle(0, 0, Browser.Width, Browser.Height));
                    }
                };

                Browser.Navigate("file://C:/Users/Lukas/Documents/gui.html");

                var context = new ApplicationContext();
                Application.Run();
            });

            BrowserThread.SetApartmentState(ApartmentState.STA);
            BrowserThread.Start();
        }
Exemple #2
0
        static void Main(string[] args)
        {
            System.Console.WriteLine("Create your own web history images.");
            System.Console.WriteLine("Type the URL (with http://...");
            string url = System.Console.ReadLine();
            System.Console.WriteLine(@"Save to location (e.g. C:\Images\)");
            string path = System.Console.ReadLine();
            IArchiveService service = new WebArchiveService();
            Website result = service.Load(url);
            System.Console.WriteLine("WebArchive Sites found: " + result.ArchiveWebsites.Count);
            WebBrowser wb = new WebBrowser();  
            int i = 0;
            foreach (ArchiveWebsite site in result.ArchiveWebsites)
            {
             i++;
             System.Console.WriteLine("Save image (Date " + site.Date.ToShortDateString() + ") number: " + i.ToString());
             wb.ScrollBarsEnabled = false;  
             wb.ScriptErrorsSuppressed = true;
             wb.Navigate(site.ArchiveUrl);  
             while (wb.ReadyState != WebBrowserReadyState.Complete) { Application.DoEvents(); }     
             wb.Width = wb.Document.Body.ScrollRectangle.Width;  
             wb.Height = wb.Document.Body.ScrollRectangle.Height;  
  
             Bitmap bitmap = new Bitmap(wb.Width, wb.Height);  
             wb.DrawToBitmap(bitmap, new Rectangle(0, 0, wb.Width, wb.Height));  
             bitmap.Save(path + site.Date.Year.ToString() + "_" + site.Date.Month.ToString() + "_" + site.Date.Day.ToString() + ".bmp");  
            }
            wb.Dispose();

            System.Console.WriteLine(result.Url);
        }
        public static Bitmap GetScreenshot(Uri uri, int width, int height)
        {
            Bitmap bitmap;

            using (var webBrowser = new WebBrowser())
            {
                webBrowser.ScrollBarsEnabled = false;
                webBrowser.ScriptErrorsSuppressed = true;

                webBrowser.Navigate(uri);

                while (webBrowser.ReadyState != WebBrowserReadyState.Complete)
                {
                    Application.DoEvents();
                }

                webBrowser.Width = width > 0
                    ? width
                    : webBrowser.Document.Body.ScrollRectangle.Width;

                webBrowser.Height = height > 0
                    ? height
                    : webBrowser.Document.Body.ScrollRectangle.Height;

                if (webBrowser.Height <= 0)
                    webBrowser.Height = 768;

                bitmap = new Bitmap(webBrowser.Width, webBrowser.Height);
                webBrowser.DrawToBitmap(bitmap,
                                        new Rectangle(0, 0, webBrowser.Width,
                                                      webBrowser.Height));
            }

            return bitmap;
        }
Exemple #4
0
        //  Thumbnail thumbnail = new Thumbnail(html, 800, 600, width, height, Thumbnail.ThumbnailMethod.Html);

        /*public Bitmap GenerateThumbnail()
         * {
         *  Thread thread = new Thread(new ThreadStart(CaptureWebPage));
         *  thread.SetApartmentState(ApartmentState.STA);
         *  thread.Start();
         *  thread.Join();
         *  return ThumbnailImage;
         * }*/
        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
        }
Exemple #5
0
        public Bitmap GenerateScreenshot(string url, int width, int height)
        {
            WebBrowser wb = new WebBrowser();
            wb.NewWindow += wb_NewWindow;
            wb.ScrollBarsEnabled = false;
            wb.ScriptErrorsSuppressed = true;
            wb.Navigate(url);
            while (wb.ReadyState != WebBrowserReadyState.Complete) { Application.DoEvents(); }

            Thread.Sleep(int.Parse(ConfigurationSettings.AppSettings["WaitForLoadWebSite"].ToString().Trim()));

            wb.Width = width;
            wb.Height = height;

            if (width == -1)
            {

                wb.Width = wb.Document.Body.ScrollRectangle.Width;
            }

            if (height == -1)
            {

                wb.Height = wb.Document.Body.ScrollRectangle.Height;
            }

            Bitmap bitmap = new Bitmap(wb.Width, wb.Height);
            wb.DrawToBitmap(bitmap, new Rectangle(0, 0, wb.Width, wb.Height));
            wb.Dispose();
            return bitmap;
        }
Exemple #6
0
        static void Main(string[] args)
        {
            WebBrowser wb = new WebBrowser();
            wb.ScrollBarsEnabled = false;
            wb.ScriptErrorsSuppressed = true;
            wb.Navigate("http://code-inside.de");
            while (wb.ReadyState != WebBrowserReadyState.Complete) { Application.DoEvents(); }

            wb.Width = wb.Document.Body.ScrollRectangle.Width;
            wb.Height = wb.Document.Body.ScrollRectangle.Height;

            Bitmap bitmap = new Bitmap(wb.Width, wb.Height);
            wb.DrawToBitmap(bitmap, new Rectangle(0, 0, wb.Width, wb.Height));
            wb.Dispose();

            bitmap.Save("C://screenshot.bmp");

        }
        protected void GetWebPageWorker()
        {
            using (var browser = new WebBrowser())
            {
                browser.ScrollBarsEnabled = false;
                browser.ScriptErrorsSuppressed = true;
                browser.Navigate(_url);

                // Wait for control to load page
                while (browser.ReadyState != WebBrowserReadyState.Complete)
                    Application.DoEvents();
                browser.ClientSize = new Size(1280, 1024);
                Thread.Sleep(1000);

                bitmap = new Bitmap(1280, 1024);
                browser.DrawToBitmap(bitmap, new Rectangle(0, 0, browser.Width, browser.Height));
                browser.Dispose();
            }
        }
Exemple #8
0
        internal static Image ExtractSnapshot(WebBrowser browser)
        {
            browser.ClientSize = new Size(850, 1500);

            Rectangle bounds = browser.Document.Body.ScrollRectangle;
            IHTMLElement2 body = browser.Document.Body.DomElement as IHTMLElement2;
            IHTMLElement2 doc = (browser.Document.DomDocument as IHTMLDocument3).documentElement as IHTMLElement2;
            int scrollHeight = Math.Max(body.scrollHeight, bounds.Height);
            int scrollWidth = Math.Max(body.scrollWidth, bounds.Width);
            scrollHeight = Math.Max(body.scrollHeight, scrollHeight);
            scrollWidth = Math.Max(doc.scrollWidth, scrollWidth);
            Rectangle finalBounds = new Rectangle(0, 0, scrollWidth, scrollHeight);

            browser.ClientSize = finalBounds.Size;
            var bitmap = new Bitmap(scrollWidth, scrollHeight);
            browser.BringToFront();
            browser.DrawToBitmap(bitmap, finalBounds);

            return bitmap;
        }
Exemple #9
0
        public void DoCapture(String url, int width = 1024, int height = 768)
        {
            try
            {
               
                WebBrowser browser = new WebBrowser();
                browser.ScrollBarsEnabled = false;
                browser.ScriptErrorsSuppressed = true;
                browser.Navigate(url);
                while (browser.ReadyState != WebBrowserReadyState.Complete) { Application.DoEvents(); }

                // Set the size of the WebBrowser control
                browser.Width = width;
                browser.Height = height;

                if (width == -1)
                {
                    // get image with full width
                    browser.Width = browser.Document.Body.ScrollRectangle.Width;
                }

                if (height == -1)
                {
                    //get image with full height
                    browser.Height = browser.Document.Body.ScrollRectangle.Height;
                }

               
                Bitmap bitmap = new Bitmap(browser.Width, browser.Height);
                browser.DrawToBitmap(bitmap, new Rectangle(0, 0, browser.Width, browser.Height));
                browser.Dispose();
                result= bitmap;
            }
            catch (Exception ex)
            {
                result= null;

            }
          
        }
        public void GenerateBitmapMobile(string url, string name)
        {
            System.Windows.Forms.WebBrowser wb = new System.Windows.Forms.WebBrowser();
            wb.ScrollBarsEnabled      = false;
            wb.ScriptErrorsSuppressed = true;
            wb.Width  = wb.Document.Body.ScrollRectangle.Width;
            wb.Height = wb.Document.Body.ScrollRectangle.Height;

            wb.Navigate(url);
            while (wb.ReadyState != WebBrowserReadyState.Complete)
            {
                System.Windows.Forms.Application.DoEvents();
            }

            Bitmap bitmap = new Bitmap(wb.Width, wb.Height);

            wb.DrawToBitmap(bitmap, new Rectangle(0, 0, wb.Width, wb.Height));
            wb.Dispose();
            var savePath = screenshotFolder + @"\" + name + "-mobile.jpg";

            bitmap.Save(savePath, ImageFormat.Jpeg);
        }
 static void Main(string[] args)
 {
     _wb = new WebBrowser { ScrollBarsEnabled = false, ScriptErrorsSuppressed = true };
     _wb.Navigate("http://www.shirdisaibabaaz.org/Reports/RegularReceipts");
     while (_wb.ReadyState != WebBrowserReadyState.Complete)
     {
         Application.DoEvents();
     }
     System.Threading.Thread.Sleep(1000);
     if (_wb.Document != null)
     {
         if (_wb.Document.Body != null)
         {
             int width = _wb.Document.Body.ScrollRectangle.Width;
             int height = _wb.Document.Body.ScrollRectangle.Height;
             _wb.Width = width;
             _wb.Height = height;
             var bmp = new Bitmap(width, height);
             _wb.DrawToBitmap(bmp, new Rectangle(0, 0, width, height));
             bmp.Save(@"C:\Users\Santhosh\Desktop\test.bmp");
         }
     }
 }
Exemple #12
0
        public void pptThumbnail(string sourceFile, string targetFile, int thumbW, int thumbH)
        {
            // Open the document and convert into HTML pages
            Microsoft.Office.Interop.PowerPoint.Application oApp = new Microsoft.Office.Interop.PowerPoint.Application();

            PowerPoint.Presentation oDoc = oApp.Presentations.Open(
                sourceFile,
                Microsoft.Office.Core.MsoTriState.msoTrue, // read only
                Microsoft.Office.Core.MsoTriState.msoTrue, // untitled
                Microsoft.Office.Core.MsoTriState.msoFalse); // with window
            string tmpHtmlFile = System.IO.Path.GetTempFileName() + ".html";
            oApp.Presentations[1].SaveCopyAs(
                tmpHtmlFile,
                PowerPoint.PpSaveAsFileType.ppSaveAsHTML, // format
                Microsoft.Office.Core.MsoTriState.msoTrue); // embed true type font

            // Create the thumbnail from the HTML pages
            Size browserSize = new Size(800, 800);
            WebBrowser browser = new WebBrowser();
            browser.Size = browserSize;
            browser.Navigate(tmpHtmlFile);
            while (WebBrowserReadyState.Complete != browser.ReadyState)
            {
                Application.DoEvents();
            }
            Bitmap bm = new Bitmap(browserSize.Width, browserSize.Height);
            browser.DrawToBitmap(bm,
                new Rectangle(0, 0, browserSize.Width, browserSize.Height));
            Bitmap thumbnail = new Bitmap(thumbW, thumbH);
            Graphics g = Graphics.FromImage(thumbnail);
            g.DrawImage(
                bm,
                new Rectangle(0, 0, thumbnail.Width, thumbnail.Height),
                new Rectangle(0, 0, browserSize.Width, browserSize.Height),
                GraphicsUnit.Pixel);
            thumbnail.Save(targetFile);
        }
Exemple #13
0
 public Bitmap GenerateScreenshot(string url, int width, int height) { 
     // Load the webpage into a WebBrowser control 
     WebBrowser wb = new WebBrowser(); 
     wb.ScrollBarsEnabled = false; 
     wb.ScriptErrorsSuppressed = true; wb.Navigate(url);  
     while (wb.ReadyState != WebBrowserReadyState.Complete) 
     { 
         System.Windows.Forms.Application.DoEvents();                
     }
     // Set the size of the 
     wb.Width = width; wb.Height = height;   
     if (width == -1) { 
         // Take Screenshot of the web pages full width 
         wb.Width = wb.Document.Body.ScrollRectangle.Width; 
     }   
     if (height == -1) 
     { 
             // Take Screenshot of the web pages full height 
             wb.Height = wb.Document.Body.ScrollRectangle.Height; 
     }   
     // Get a Bitmap representation of the webpage as it's rendered in the WebBrowser control 
     Bitmap bitmap = new Bitmap(wb.Width, wb.Height); wb.DrawToBitmap(bitmap, new Rectangle(0, 0, wb.Width, wb.Height)); wb.Dispose();  
     return bitmap; 
 }
Exemple #14
0
        private void GetThumbnail()
        {
            int wm = int.MaxValue;
            int hm = int.MaxValue;

            foreach (var screen in Screen.AllScreens)
            {
                wm = Math.Min(screen.Bounds.Width,  wm);
                hm = Math.Min(screen.Bounds.Height, hm);
            }

            try
            {
                using (var web = new WebBrowser())
                {
                    web.ScrollBarsEnabled		= false;
                    web.ScriptErrorsSuppressed	= true;

                    DateTime start = DateTime.UtcNow;
                    web.Navigate(m_url);

                    while (web.ReadyState != WebBrowserReadyState.Complete && (DateTime.UtcNow -start).TotalSeconds < 30)
                        Application.DoEvents();

                    int w, h;

                    try
                    {
                        dynamic doc = web.Document.DomDocument;
                        dynamic body = web.Document.Body;
                        body.DomElement.contentEditable = true;
                        doc.documentElement.style.overflow = "hidden";
                    }
                    catch
                    { }

                    try
                    {
                        w = Math.Min(web.Document.Body.ScrollRectangle.Width, wm);
                        h = Math.Min(web.Document.Body.ScrollRectangle.Height, hm);
                    }
                    catch
                    {
                        w = Math.Min(web.Document.Body.ClientRectangle.Width, wm);
                        h = Math.Min(web.Document.Body.ClientRectangle.Height, hm);
                    }

                    //br.Width  = w;
                    //br.Height = h;
                    web.ClientSize = new Size(w, h);

                    m_img = new Bitmap(w, h, PixelFormat.Format24bppRgb);
                    web.DrawToBitmap(m_img, new Rectangle(0, 0, w, h));
                }
            }
            catch
            {
                if (this.m_img != null)
                    this.m_img.Dispose();
            }
        }
 private void GenerateThumbnailFromCompletedPage(WebBrowser m_WebBrowser)
 {
     m_WebBrowser.ClientSize = new Size(this.m_BrowserWidth, this.m_BrowserHeight);
     m_WebBrowser.ScrollBarsEnabled = false;
     m_Bitmap = new Bitmap(m_WebBrowser.Bounds.Width, m_WebBrowser.Bounds.Height);
     m_WebBrowser.BringToFront();
     m_WebBrowser.DrawToBitmap(m_Bitmap, m_WebBrowser.Bounds);
     m_Bitmap = (Bitmap) m_Bitmap.GetThumbnailImage(m_ThumbnailWidth, m_ThumbnailHeight, null, IntPtr.Zero);
 }
Exemple #16
0
        public BitmapImage GetImage()
        {
            BitmapImage result = null;
            if (ImageAllowed)
            {
                using (var browser = new System.Windows.Forms.WebBrowser())
                {
                    browser.ScriptErrorsSuppressed = true;
                    browser.ScrollBarsEnabled = false;
                    browser.DocumentCompleted += (s, e) =>
                    {

                        var width = browser.Document.InvokeScript("eval", new object[] { @"
            function documentWidth(){
            return Math.max(
            document.documentElement['clientWidth'],
            document.body['scrollWidth'], document.documentElement['scrollWidth'],
            document.body['offsetWidth'], document.documentElement['offsetWidth']
            );
            }
            documentWidth();
            "});
                        var height = browser.Document.InvokeScript("eval", new object[] { @"
            function documentHeight(){
            return Math.max(
            document.documentElement['clientHeight'],
            document.body['scrollHeight'], document.documentElement['scrollHeight'],
            document.body['offsetHeight'], document.documentElement['offsetHeight']
            );
            }
            documentHeight();
            "});

                        if (height != null && width != null)
                        {
                            browser.Height = int.Parse(height.ToString());
                            browser.Width = int.Parse(width.ToString());
                            using (var pic = new Bitmap(browser.Width, browser.Height))
                            {

                                browser.Focus();
                                browser.DrawToBitmap(pic, new System.Drawing.Rectangle(0, 0, pic.Width, pic.Height));
                                var strm = new MemoryStream();
                                pic.Save(strm, System.Drawing.Imaging.ImageFormat.Jpeg);
                                strm.Seek(0, SeekOrigin.Begin);
                                result = new BitmapImage();
                                result.BeginInit();
                                result.StreamSource = strm;
                                result.DecodePixelHeight = 300;
                                result.EndInit();
                            }
                        }
                        else
                        {
                            result = new System.Windows.Media.Imaging.BitmapImage(new Uri(_url));
                        }
                    };

                    browser.Navigate(_url);
                    while (browser.ReadyState != System.Windows.Forms.WebBrowserReadyState.Complete)
                    {
                        System.Windows.Forms.Application.DoEvents();
                    }
                }
            }
            else
            {
                result = new System.Windows.Media.Imaging.BitmapImage(new Uri(_url));
            }
            return result;
        }
Exemple #17
0
        public BitmapImage GetImage()
        {
            BitmapImage result = null;

            if (ImageAllowed)
            {
                using (var browser = new System.Windows.Forms.WebBrowser())
                {
                    browser.ScriptErrorsSuppressed = true;
                    browser.ScrollBarsEnabled      = false;
                    browser.DocumentCompleted     += (s, e) =>
                    {
                        var width  = browser.Document.InvokeScript("eval", new object[] { @"
function documentWidth(){
	return Math.max(
		document.documentElement['clientWidth'],
		document.body['scrollWidth'], document.documentElement['scrollWidth'],
		document.body['offsetWidth'], document.documentElement['offsetWidth']
	);
}
documentWidth();
" });
                        var height = browser.Document.InvokeScript("eval", new object[] { @"
function documentHeight(){
	return Math.max(
		document.documentElement['clientHeight'],
		document.body['scrollHeight'], document.documentElement['scrollHeight'],
		document.body['offsetHeight'], document.documentElement['offsetHeight']
	);
}
documentHeight();
" });

                        if (height != null && width != null)
                        {
                            browser.Height = int.Parse(height.ToString());
                            browser.Width  = int.Parse(width.ToString());
                            using (var pic = new Bitmap(browser.Width, browser.Height))
                            {
                                browser.Focus();
                                browser.DrawToBitmap(pic, new System.Drawing.Rectangle(0, 0, pic.Width, pic.Height));
                                var strm = new MemoryStream();
                                pic.Save(strm, System.Drawing.Imaging.ImageFormat.Jpeg);
                                strm.Seek(0, SeekOrigin.Begin);
                                result = new BitmapImage();
                                result.BeginInit();
                                result.StreamSource      = strm;
                                result.DecodePixelHeight = 300;
                                result.EndInit();
                            }
                        }
                        else
                        {
                            result = new System.Windows.Media.Imaging.BitmapImage(new Uri(_url));
                        }
                    };

                    browser.Navigate(_url);
                    while (browser.ReadyState != System.Windows.Forms.WebBrowserReadyState.Complete)
                    {
                        System.Windows.Forms.Application.DoEvents();
                    }
                }
            }
            else
            {
                result = new System.Windows.Media.Imaging.BitmapImage(new Uri(_url));
            }
            return(result);
        }
        static byte[] CaptureWebPageBytesP(string body, int width, int height)
        {
            byte[] data;

            using (WebBrowser web = new WebBrowser())
            {
                web.ScrollBarsEnabled = false; // no scrollbars
                web.ScriptErrorsSuppressed = true; // no errors

                web.DocumentText = body;
                while (web.ReadyState != System.Windows.Forms.WebBrowserReadyState.Complete)
                    System.Windows.Forms.Application.DoEvents();

                web.Width = web.Document.Body.ScrollRectangle.Width;
                web.Height = web.Document.Body.ScrollRectangle.Height;

                // a bitmap that we will draw to
                using (System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(web.Width, web.Height))
                {
                    // draw the web browser to the bitmap
                    web.DrawToBitmap(bmp, new Rectangle(web.Location.X, web.Location.Y, web.Width, web.Height));
                    // draw the web browser to the bitmap

                    GraphicsUnit units = GraphicsUnit.Pixel;
                    RectangleF destRect = new RectangleF(0F, 0F, width, height);
                    RectangleF srcRect = new RectangleF(0, 0, web.Width, web.Width * 1.5F);

                    Bitmap b = new Bitmap(width, height);
                    Graphics g = Graphics.FromImage((Image)b);
                    g.Clear(Color.White);
                    g.InterpolationMode = InterpolationMode.HighQualityBicubic;

                    g.DrawImage(bmp, destRect, srcRect, units);
                    g.Dispose();

                    using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
                    {
                        EncoderParameter qualityParam = null;
                        EncoderParameters encoderParams = null;
                        try
                        {
                            ImageCodecInfo imageCodec = null;
                            imageCodec = GetEncoderInfo("image/jpeg");

                            qualityParam = new EncoderParameter(Encoder.Quality, 100L);

                            encoderParams = new EncoderParameters(1);
                            encoderParams.Param[0] = qualityParam;
                            b.Save(stream, imageCodec, encoderParams);
                        }
                        catch (Exception)
                        {
                            throw new Exception();
                        }
                        finally
                        {
                            if (encoderParams != null) encoderParams.Dispose();
                            if (qualityParam != null) qualityParam.Dispose();
                        }
                        b.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
                        stream.Position = 0;
                        data = new byte[stream.Length];
                        stream.Read(data, 0, (int)stream.Length);
                    }
                }
            }
            return data;
        }
Exemple #19
0
 /// <summary>
 /// Creates a WebBrowser control to generate the thumbnail image
 /// Must be called from a single-threaded apartment
 /// </summary>
 protected void GetThumbnailWorker()
 {
     using (WebBrowser browser = new WebBrowser())
     {
         var stopWatch = new System.Diagnostics.Stopwatch();
         stopWatch.Start();
         browser.ClientSize = new Size(BrowserWidth, BrowserHeight);
         browser.ScrollBarsEnabled = false;
         browser.ScriptErrorsSuppressed = true;
         browser.Navigate(Url);
         //browser.AllowNavigation = false;
         // Wait for control to load page
         int counter = 0;
         while (browser.ReadyState != WebBrowserReadyState.Complete)
         {
             Application.DoEvents();
             if (browser.ReadyState == WebBrowserReadyState.Interactive || browser.ReadyState == WebBrowserReadyState.Loaded)
             {
                 counter++;
             }
             if (stopWatch.Elapsed > TimeSpan.FromSeconds(4))
             {
                 break;
             }
             if (counter == 100000)
             {
                 break;
             }
         }
         stopWatch.Stop();
         // Render browser content to bitmap
         _bmp = new Bitmap(BrowserWidth, BrowserHeight);
         browser.DrawToBitmap(_bmp, new Rectangle(0, 0, BrowserWidth, BrowserHeight));
         //browser.AllowNavigation = true;
     }
 }
 private Bitmap GetPreviewImage()
 {
     WebBrowser wb = new WebBrowser();
     wb.ScrollBarsEnabled = false;
     wb.Size = new Size(Width, Height);
     wb.ScriptErrorsSuppressed = true;
     wb.NewWindow += new System.ComponentModel.CancelEventHandler(wb_NewWindow);
     wb.Navigate(_url);
     // wait for it to load
     while (wb.ReadyState != WebBrowserReadyState.Complete)
     {
         Application.DoEvents();
     }
     Bitmap bitmap = new Bitmap(Width, Height);
     Rectangle rect = new Rectangle(0, 0, Width, Height);
     wb.DrawToBitmap(bitmap, rect);
     wb.Dispose();
     return bitmap;
 }
        private static void Main()
        {
            int width = -1;
            int height = -1;

            var wb = new WebBrowser { AllowNavigation = true, ScrollBarsEnabled = false, ScriptErrorsSuppressed = true };
            wb.Navigate("http://tillidsoft.com");
            while (wb.ReadyState != WebBrowserReadyState.Complete)
            { }
            // Set the size of the WebBrowser control
            wb.Width = width;
            wb.Height = height;
            if (wb.Document != null && wb.Document.Body != null)
            {
                if (width == -1)
                {
                    // Take Screenshot of the web pages full width
                    wb.Width = wb.Document.Body.ScrollRectangle.Width;
                }
                if (height == -1)
                {
                    // Take Screenshot of the web pages full height
                    wb.Height = wb.Document.Body.ScrollRectangle.Height;
                }

                // Get a Bitmap representation of the webpage as it's rendered in the WebBrowser control
                var bitmap = new Bitmap(wb.Width, wb.Height);
                wb.DrawToBitmap(bitmap, new Rectangle(0, 0, wb.Width, wb.Height));
                wb.Dispose();

                bitmap.Save(@"C:\Users\santhosh\Desktop\TaskScheduler\1.png", System.Drawing.Imaging.ImageFormat.Png);
            }
            return;

            //// Get the service on the local machine
            //using (var ts = new TaskService())
            //{
            //    if (ts.RootFolder.GetTasks().Any(task => task.Name == "BethedaContentSync"))
            //    {
            //        ts.RootFolder.DeleteTask("BethedaContentSync");
            //    }

            //    // Create a new task definition and assign properties
            //    TaskDefinition td = ts.NewTask();
            //    td.RegistrationInfo.Description = "Bethesda Employee, Patient and Physician import task.";

            //    // Create a trigger that will fire the task at this time every day
            //    //td.Triggers.Add(new DailyTrigger { StartBoundary = DateTime.Now.AddHours(-DateTime.Now.Hour), DaysInterval = 1, Enabled = true });
            //    td.Triggers.Add(new DailyTrigger { StartBoundary = DateTime.Now.AddSeconds(5), DaysInterval = 1, Enabled = true });

            //    string path = @"C:\Program Files\Internet Explorer\iexplore.exe";

            //    // Create an action that will launch Notepad whenever the trigger fires
            //    td.Actions.Add(new ExecAction(path, "", null));

            //    // Register the task in the root folder
            //    ts.RootFolder.RegisterTaskDefinition(@"BethedaContentSync", td);
            //}

            return;
            var consentFormSvcClient = new ConsentFormSvcClient();
            consentFormSvcClient.CreateLog("Sanhtosh", LogType.E, "Test", "Some desc");

            return;
            const string localConStr = "server=192.168.1.158;database=bethesdaCollege;uid=sa;pwd=sa@123";
            const string bethesdaConStr = "server=192.168.1.93;database=Soarian_Clin_Tst_1;uid=sa;pwd=sa@123";

            using (var sqlConnectionLocal = new SqlConnection(localConStr))
            {
                sqlConnectionLocal.Open();

                using (var sqlConnectionBethesda = new SqlConnection(bethesdaConStr))
                {
                    sqlConnectionBethesda.Open();

                    # region Import Physician

                    // ---------------starts physician import process------------------

                    //                    // starts synchronizing
                    //                    var command = new SqlCommand(string.Empty, sqlConnectionBethesda)
                    //                    {
                    //                        //CommandText = "select user_oid,GroupName,UserDescription from [soariandbtest].[dbo].[Physician]"
                    //                        CommandText = "BMH_Consent_GetPhysicianList",
                    //                        CommandType = CommandType.StoredProcedure
                    //                    };

                    //                    var daPhysician = new SqlDataAdapter(command);

                    //                    var physiciansDs = new DataSet();
                    //                    daPhysician.Fill(physiciansDs);

                    //                    int syncId = Convert.ToInt32(DateTime.Now.Ticks % 65323);

                    //                    foreach (DataTable dataTable in physiciansDs.Tables)
                    //                    {
                    //                        foreach (DataRow dataRow in dataTable.Rows)
                    //                        {
                    //                            command = new SqlCommand("select * from Physician where Fname='" + dataRow["UserDescription"] + "'", sqlConnectionLocal);

                    //                            daPhysician = new SqlDataAdapter(command);

                    //                            var physiciansCheck = new DataSet();
                    //                            daPhysician.Fill(physiciansCheck);

                    //                            if (physiciansCheck.Tables.Count == 0 || physiciansCheck.Tables[0].Rows.Count == 0)
                    //                            {
                    //                                string physicianName = dataRow["UserDescription"].ToString();
                    //                                string userId = dataRow["user_oid"].ToString();
                    //                                string groupName = dataRow["GroupName"].ToString();

                    //                                command = new SqlCommand(@"insert into Physician
                    //                                                                                values('False','True',8,'" + physicianName + "','" + userId +
                    //                                                            "',0,'" + groupName + "'," + syncId + ")", sqlConnectionLocal);
                    //                                command.ExecuteNonQuery();
                    //                            }
                    //                        }
                    //                    }

                    //                    // removing un - available physicians
                    //                    command = new SqlCommand("delete from Physician where SyncID !=" + syncId, sqlConnectionLocal);
                    //                    command.ExecuteNonQuery();

                    #endregion

                    #region Import Patients for BHE location

                    //AddPatient(sqlConnectionLocal, sqlConnectionBethesda, "BHE");

                    //AddPatient(sqlConnectionLocal, sqlConnectionBethesda, "BMH");

                    #endregion

                    #region Import Employee

                    // ---------------starts physician import process------------------

                    // starts synchronizing
                    var commandEmployee = new SqlCommand(string.Empty, sqlConnectionBethesda)
                    {
                        //CommandText = "select user_oid,GroupName,UserDescription from [soariandbtest].[dbo].[Physician]"
                        CommandText = "BMH_Consent_User",
                        CommandType = CommandType.StoredProcedure
                    };

                    var daEmployee = new SqlDataAdapter(commandEmployee);

                    var employeeDs = new DataSet();
                    daEmployee.Fill(employeeDs);

                    int syncIdEmployee = Convert.ToInt32(DateTime.Now.Ticks % 65323);

                    foreach (DataTable dataTable in employeeDs.Tables)
                    {
                        foreach (DataRow dataRow in dataTable.Rows)
                        {
                            commandEmployee = new SqlCommand("select * from EmployeeInformation where EmpID='" + dataRow["LoginID"] + "'", sqlConnectionLocal);

                            daEmployee = new SqlDataAdapter(commandEmployee);

                            var physiciansCheck = new DataSet();
                            daEmployee.Fill(physiciansCheck);

                            if (physiciansCheck.Tables.Count == 0 || physiciansCheck.Tables[0].Rows.Count == 0)
                            {
                                string lastName = dataRow["LastName"].ToString();
                                string firstName = dataRow["FirstName"].ToString();
                                string loginID = dataRow["LoginID"].ToString();

                                commandEmployee = new SqlCommand(@"insert into EmployeeInformation
                                           values('" + loginID + "','" + lastName + "','" + firstName + "','" + syncIdEmployee + "')", sqlConnectionLocal);
                                commandEmployee.ExecuteNonQuery();
                            }
                        }
                    }

                    // removing un - available physicians
                    commandEmployee = new SqlCommand("delete from EmployeeInformation where SyncID !=" + syncIdEmployee, sqlConnectionLocal);
                    commandEmployee.ExecuteNonQuery();

                    #endregion
                }
            }
        }
        private static Image RenderOperationWithBrowser(TemplateObject to, string htmlToRender, Size size)
        {
            using (WebBrowser w = new WebBrowser())
            {
                w.AllowNavigation = true;
                w.ScrollBarsEnabled = false;
                w.ScriptErrorsSuppressed = true;

                w.DocumentText = htmlToRender;

                while (w.ReadyState != WebBrowserReadyState.Complete)
                {
                    // Pump the message queue for the web browser.
                    Application.DoEvents();
                }

                // Set the size of the WebBrowser control
                int suggestedWidth = w.Document.Body.ScrollRectangle.Width;
                int suggestedHeight = w.Document.Body.ScrollRectangle.Height;

                int realWidth = (suggestedWidth < size.Width) ? suggestedWidth : size.Width;
                int realHeight = (suggestedHeight < size.Height) ? suggestedHeight : size.Height;

                // If any of the Size-properties is set to zero, use the full size part.
                w.Width = (realWidth > 0) ? realWidth : suggestedWidth;
                w.Height = (realHeight > 0) ? realHeight : suggestedHeight;

                // Get a Bitmap representation of the webpage as it's rendered in the WebBrowser control
                using (Bitmap bitmap = new Bitmap(w.Width, w.Height))
                {
                    w.DrawToBitmap(bitmap, new Rectangle(0, 0, w.Width, w.Height));
                    return (Image)bitmap.Clone();
                }
            }
        }