I have html
source and I want to convert to image in asp.net
.
My html source come from database eg.
<table border="0" cellpadding="0" cellspacing="0" width="658" style="border-collapse: collapse;width:494pt"> <colgroup><col width="146" style="mso-width-source:userset;mso-width-alt:5339;width:110pt" /> <col width="64" span="8" style="width:48pt" /> </colgroup>
<tbody>
<tr height="undefined" style="height:15.0pt">
<td height="20" width="146" style="height:15.0pt;width:110pt"></td>
<td width="64" style="width:48pt"></td>
<td width="64" style="width:48pt"></td>
<td class="xl65" align="right" width="64" style="width:48pt">Jfhn-20</td>
<td class="xl65" align="right" width="64" style="width:48pt">Jfhan-40</td>
<td class="xl65" align="right" width="64" style="width:48pt">Jaghn-80</td>
<td class="xl66" width="64" style="width:48pt">1/160</td>
<td class="xl66" width="64" style="width:48pt">fgh1/320</td>
<td class="xl66" width="64" style="width:48pt">1/640</td> </tr>
<tr height="undefined" style="height:15.0pt">
<td height="20" class="xl66" style="height:15.0pt">S.Typhi-O:</td>
<td class="xl66"></td>
<td></td>
<td class="xl66">#</td>
<td class="xl66">#</td>
<td class="xl66">#</td>
<td class="xl66">#</td>
<td class="xl66">#</td>
<td class="xl66">#</td> </tr>
<tr height="undefined" style="height:15.0pt">
<td height="20" class="xl66" style="height:15.0pt">S.Typhi-H:</td>
<td class="xl66"></td>
<td></td>
<td class="xl66">#</td>
<td class="xl66">#</td>
<td class="xl66">#</td>
<td class="xl66">#</td>
<td class="xl66">#</td>
<td class="xl66">#</td> </tr>
<tr height="undefined" style="height:15.0pt">
<td height="20" class="xl66" style="height:15.0pt">S.Paratyphi-AH:</td>
<td class="xl66">#</td>
<td class="xl66">#</td>
<td class="xl66">#</td>
<td class="xl66">#</td>
<td class="xl66">#</td>
<td class="xl66">#</td>
<td></td>
<td></td> </tr>
<tr height="undefined" style="height:15.0pt">
<td height="20" class="xl66" style="height:15.0pt">S.Paratyphi-BH:</td>
<td class="xl66">#</td>
<td class="xl66">#</td>
<td class="xl66">#</td>
<td class="xl66">#</td>
<td class="xl66">#</td>
<td class="xl66">#</td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
I want to convert into image. I am using code
private static void StartBrowser(string source)
{
var th = new Thread(() =>
{
var webBrowser = new WebBrowser();
webBrowser.ScrollBarsEnabled = false;
webBrowser.DocumentCompleted += webBrowser_DocumentCompleted;
webBrowser.DocumentText = source;
Application.Run();
});
th.SetApartmentState(ApartmentState.STA);
th.Start();
}
static void webBrowser_DocumentCompleted(
object sender,
WebBrowserDocumentCompletedEventArgs e)
{
var webBrowser = (WebBrowser)sender;
using (Bitmap bitmap =
new Bitmap(webBrowser.Width, webBrowser.Height))
{
webBrowser.DrawToBitmap(
bitmap,
new System.Drawing
.Rectangle(0, 0, bitmap.Width, bitmap.Height));
bitmap.Save(@"c:\\filename.jpg",
System.Drawing.Imaging.ImageFormat.Jpeg);
}
}
but it show error given below :
"Error HRESULT E_FAIL has been returned from a call to a COM component"
at the below line
webBrowser.DocumentText = source;
suggest me how to convert html source code to image in asp.net