Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6714039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:26:58+00:00 2026-05-26T08:26:58+00:00

I am trying to capture the following page using standard c# .net code. I’ve

  • 0

I am trying to capture the following page using standard c# .net code. I’ve searched around for people’s various methods, most of which involve instantiating a browser object and using a draw to bitmap method. However, none of these pick up the contents of the chart on this page:

http://www.highcharts.com/demo/combo-dual-axes

Perhaps the javascript doesn’t have time to run, but adding Thread.Sleep(x) hasn’t assisted.

This commercial component captures it correctly, but I’d rather avoid requiring an additional dependency in my project and paying $150 when the other solutions are sooo close!.

Anyone find their solution renders this correctly?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T08:26:58+00:00Added an answer on May 26, 2026 at 8:26 am

    You have possibly tried IECapt. I think it is the right way to go. I created a modified version of it and use a timer instead of Thread.Sleep it captures your site as expected.

    ——EDIT——

    Here is the ugly source. Just Add a reference to Microsoft HTML Object Library.

    And this is the usage:

    HtmlCapture capture = new HtmlCapture(@"c:\temp\myimg.png");
    capture.HtmlImageCapture += new HtmlCapture.HtmlCaptureEvent(capture_HtmlImageCapture);
    capture.Create("http://www.highcharts.com/demo/combo-dual-axes");
    
    void capture_HtmlImageCapture(object sender, Uri url)
    {
        this.Close();
    }
    

    File1

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.IO;
    
    
    namespace MyIECapt
    {
        public class HtmlCapture
        {
            private WebBrowser web;
            private Timer tready;
            private Rectangle screen;
            private Size? imgsize = null;
    
            //an event that triggers when the html document is captured
            public delegate void HtmlCaptureEvent(object sender, Uri url);
    
            public event HtmlCaptureEvent HtmlImageCapture;
    
            string fileName = "";
    
            //class constructor
            public HtmlCapture(string fileName)
            {
                this.fileName = fileName;
    
                //initialise the webbrowser and the timer
                web = new WebBrowser();
                tready = new Timer();
                tready.Interval = 2000;
                screen = Screen.PrimaryScreen.Bounds;
                //set the webbrowser width and hight
                web.Width = 1024; //screen.Width;
                web.Height = 768; // screen.Height;
                //suppress script errors and hide scroll bars
                web.ScriptErrorsSuppressed = true;
                web.ScrollBarsEnabled = false;
                //attached events
                web.Navigating +=
                  new WebBrowserNavigatingEventHandler(web_Navigating);
                web.DocumentCompleted += new
                  WebBrowserDocumentCompletedEventHandler(web_DocumentCompleted);
                tready.Tick += new EventHandler(tready_Tick);
            }
    
    
            public void Create(string url)
            {
                imgsize = null;
                web.Navigate(url);
            }
    
            public void Create(string url, Size imgsz)
            {
                this.imgsize = imgsz;
                web.Navigate(url);
            }
    
    
    
            void web_DocumentCompleted(object sender,
                     WebBrowserDocumentCompletedEventArgs e)
            {
                //start the timer
                tready.Start();
            }
    
            void web_Navigating(object sender, WebBrowserNavigatingEventArgs e)
            {
                //stop the timer   
                tready.Stop();
            }
    
    
    
            void tready_Tick(object sender, EventArgs e)
            {
                try
                {
                    //stop the timer
                    tready.Stop();
    
                    mshtml.IHTMLDocument2 docs2 = (mshtml.IHTMLDocument2)web.Document.DomDocument;
                    mshtml.IHTMLDocument3 docs3 = (mshtml.IHTMLDocument3)web.Document.DomDocument;
                    mshtml.IHTMLElement2 body2 = (mshtml.IHTMLElement2)docs2.body;
                    mshtml.IHTMLElement2 root2 = (mshtml.IHTMLElement2)docs3.documentElement;
    
                    // Determine dimensions for the image; we could add minWidth here
                    // to ensure that we get closer to the minimal width (the width
                    // computed might be a few pixels less than what we want).
                    int width = Math.Max(body2.scrollWidth, root2.scrollWidth);
                    int height = Math.Max(root2.scrollHeight, body2.scrollHeight);
    
                    //get the size of the document's body
                    Rectangle docRectangle = new Rectangle(0, 0, width, height);
    
                    web.Width = docRectangle.Width;
                    web.Height = docRectangle.Height;
    
                    //if the imgsize is null, the size of the image will 
                    //be the same as the size of webbrowser object
                    //otherwise  set the image size to imgsize
                    Rectangle imgRectangle;
                    if (imgsize == null) imgRectangle = docRectangle;
                    else imgRectangle = new Rectangle() { Location = new Point(0, 0), Size = imgsize.Value };
    
                    //create a bitmap object 
                    Bitmap bitmap = new Bitmap(imgRectangle.Width, imgRectangle.Height);
                    //get the viewobject of the WebBrowser
                    IViewObject ivo = web.Document.DomDocument as IViewObject;
    
                    using (Graphics g = Graphics.FromImage(bitmap))
                    {
                        //get the handle to the device context and draw
                        IntPtr hdc = g.GetHdc();
                        ivo.Draw(1, -1, IntPtr.Zero, IntPtr.Zero,
                                 IntPtr.Zero, hdc, ref imgRectangle,
                                 ref docRectangle, IntPtr.Zero, 0);
                        g.ReleaseHdc(hdc);
                    }
                    //invoke the HtmlImageCapture event
                    bitmap.Save(fileName);
                    bitmap.Dispose();
                }
                catch 
                {
                    //System.Diagnostics.Process.GetCurrentProcess().Kill();
                }
                if(HtmlImageCapture!=null) HtmlImageCapture(this, web.Url);
            }
        }
    }
    

    and File2

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Drawing;
    using System.Runtime.InteropServices;
    
    namespace MyIECapt
    {
        [ComVisible(true), ComImport()]
        [GuidAttribute("0000010d-0000-0000-C000-000000000046")]
        [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
        public interface IViewObject
        {
            [return: MarshalAs(UnmanagedType.I4)]
            [PreserveSig]
            int Draw(
                [MarshalAs(UnmanagedType.U4)] UInt32 dwDrawAspect,
                int lindex,
                IntPtr pvAspect,
                [In] IntPtr ptd,
                IntPtr hdcTargetDev,
                IntPtr hdcDraw,
                [MarshalAs(UnmanagedType.Struct)] ref Rectangle lprcBounds,
                [MarshalAs(UnmanagedType.Struct)] ref Rectangle lprcWBounds,
                IntPtr pfnContinue,
                [MarshalAs(UnmanagedType.U4)] UInt32 dwContinue);
            [PreserveSig]
            int GetColorSet([In, MarshalAs(UnmanagedType.U4)] int dwDrawAspect,
               int lindex, IntPtr pvAspect, [In] IntPtr ptd,
                IntPtr hicTargetDev, [Out] IntPtr ppColorSet);
            [PreserveSig]
            int Freeze([In, MarshalAs(UnmanagedType.U4)] int dwDrawAspect,
                            int lindex, IntPtr pvAspect, [Out] IntPtr pdwFreeze);
            [PreserveSig]
            int Unfreeze([In, MarshalAs(UnmanagedType.U4)] int dwFreeze);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I am trying to detect web cam in opencv using following code I
I'm trying to capture shift + tab in c# using the following cpp syntax:
I am trying to capture the following content in PHP using regular expressions: /*
I trying to capture packets using SharpPcap library. I'm able to return the packets
I am trying to capture urls in an html page that is being repeated
I have a test list that I am trying to capture data from using
I'm trying to capture standard output of a command to a file-like object in
I'm trying to capture certain parts of HTML using regular expressions, and I've come
I am using Python 2.6.5 and I am trying to capture the raw http
I'm trying to figure out how to capture an error message for the following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.