'Convert HTML file to image using web browser in windows NT service
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(576,384))
{
webBrowser.DrawToBitmap(bitmap,new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height));
bitmap.Save(@"images/" + "xxx.jpg",System.Drawing.Imaging.ImageFormat.Jpeg);
}
}
Hi Guys,
I am trying to print out an HTML file in a windows service by using the windows application web browser. For some reason, I cannot get a clear image, it draws only 25% of the image.
Note:- There is a barcode image in the upper right corner.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

