title: Generate JPEG from Html Content In Asp.Net MVC
body: <p>I want to Generate Image (JPEG) from  HTML Code Entered in Textarea or other Input Controls (Not Whole Web page) using C# in <strong>Asp.Net MVC</strong> .<strong>MVC doesn't Support WebBrowser Control.</strong> </p>
  
  <p>This HTML contains both data and image</p>
  
  <p><strong>HTML</strong></p>
  
  <pre><code>&lt;b&gt;Convert Html To Image&lt;b&gt; 
  &lt;br/&gt;
  &lt;img src="C:\Logo.jpg" alt="Smiley face" width="42" height="42"&gt; 
  </code></pre>
  
  <p>I passed the html code to the Controller for the  Bitmap Image Creating Function</p>
  
  <pre><code>private Bitmap CreateBitmapImage(string html)
  {
     Bitmap objBmpImage = new Bitmap(1, 1);
  
     int intWidth = 0;
     int intHeight = 0;
  
     // Create the Font object for the image text drawing.
     Font objFont = new Font("Arial", 20, System.Drawing.FontStyle.Bold,  System.Drawing.GraphicsUnit.Pixel);
  
     // Create a graphics object to measure the text's width and height.
     Graphics objGraphics = Graphics.FromImage(objBmpImage);
  
     // This is where the bitmap size is determined.
     intWidth = (int)objGraphics.MeasureString(html, objFont).Width;
     intHeight = (int)objGraphics.MeasureString(html, objFont).Height;
  
     // Create the bmpImage again with the correct size for the text and font.
     objBmpImage = new Bitmap(objBmpImage, new Size(intWidth, intHeight));
  
     // Add the colors to the new bitmap.
     objGraphics = Graphics.FromImage(objBmpImage);
  
     // Set Background color
     objGraphics.Clear(Color.White);
     objGraphics.SmoothingMode = SmoothingMode.AntiAlias;
     objGraphics.TextRenderingHint = TextRenderingHint.AntiAlias;
     objGraphics.DrawString(html, objFont, new SolidBrush(Color.FromArgb(102, 102, 102)), 0, 0);
     objGraphics.Flush();
     return (objBmpImage);
  }
  </code></pre>
  
  <p>But it return the Output Like this</p>
  
  <p><img src="https://i.stack.imgur.com/92GwC.png" alt="enter image description here"></p>
  
  <p><strong>But Required OutPut</strong></p>
  
  <p><img src="https://i.stack.imgur.com/Z3S6V.png" alt="enter image description here"></p>
  
  <p>Is there any way to Generate this(Stepes to Generate Image from html) or any third party Opensource Component Available like <a href="http://www.hiqpdf.com/demo/ConvertHtmlToImage.aspx" rel="nofollow noreferrer">HtmlToImageConverter</a> ? </p>