title: C# WebBrowser Generate Image ( only required data without white space ) via HTML Content
body: <p>I tried to generate Image via HTML DIV Content.<br>
  I succeeded by using below code <code>System.Windows.Forms.WebBrowser</code>.</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
  {
  string _GenerateString = @"VisualStudio&lt;sup&gt;ide test&lt;/sup&gt;";
  StringBuilder sb = new StringBuilder();           
  
  sb.Append(" &lt;style type=\"text/css\"&gt; ");
  sb.Append(" #_GenerateHTMLToImage_{ ");
  sb.Append("     width:...px; ");
  sb.Append("     height:...px; ");
  sb.Append(" } ");
  sb.Append(" &lt;/style&gt; ");
  sb.Append(" &lt;div id='_GenerateHTMLToImage_'&gt; ");
  sb.Append(_GenerateString);
  sb.Append(" &lt;/div&gt; ");
  
  //var bmp = MakeScreenshot_original(sb.ToString());
  var bmp = MakeScreenshot(sb.ToString());
  bmp.Save(@"C:\test_web.jpg");
  }
  
  public Bitmap MakeScreenshot(string html)
  {
  // Load the webpage into a WebBrowser control
  WebBrowser wb = new WebBrowser();
  
  wb.Navigate("about:blank");
  if (wb.Document != null){
      wb.Document.Write(html);
  }
  
  wb.DocumentText = html;
  wb.ScrollBarsEnabled = false;
  wb.ScriptErrorsSuppressed = true;            
  while (wb.ReadyState != WebBrowserReadyState.Complete) { 
      System.Windows.Forms.Application.DoEvents(); 
  }
  
  wb.Width = wb.Document.Body.ScrollRectangle.Width;
  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;
  } 
  </code></pre>
  
  <p>It generate me below image
  <img src="https://i.stack.imgur.com/FDchL.png" alt="enter image description here"></p>
  
  <p>But my problem is it generate image ( my required string + <b>unwanted white space</b> ).
  I don't know how to generate image only string that I want and removed any white space.</p>
  
  <p>I had changed parameter values from below lines...</p>
  
  <pre><code>Bitmap bitmap = new Bitmap(xxx, xxx);
  wb.DrawToBitmap(bitmap, new Rectangle(xxx, xxx, xxxx, xxxx));
  </code></pre>
  
  <p>But, even I had changed parameter integer values , I still not satisfy the outcome.</p>
  
  <p>Any suggestion please.</p>