I'm using these 2 Functions for generate Image from Html Code:
public static void StartBrowser(string HtmlText)
{
var th = new Thread(() =>
{
var webBrowser = new WebBrowser();
webBrowser.ScrollBarsEnabled = false;
webBrowser.IsWebBrowserContextMenuEnabled = true;
webBrowser.AllowNavigation = true;
webBrowser.DocumentCompleted += webBrowser_DocumentCompleted;
webBrowser.DocumentText = HtmlText;
Application.Run();
});
th.SetApartmentState(ApartmentState.STA);
th.Start();
}
static void webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
string path = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
var webBrowser = (WebBrowser)sender;
using (Bitmap bitmap =
new Bitmap(
webBrowser.Width=450,
webBrowser.Height=1000))
{
webBrowser
.DrawToBitmap(
bitmap,
new System.Drawing
.Rectangle(0, 0, bitmap.Width, bitmap.Height));
string imgfile = "fileimg" + DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second + ".jpg";
bitmap.Save(path + "/images/" + imgfile, System.Drawing.Imaging.ImageFormat.Jpeg);
OrderDetailRepeatedImage = path + "/images/" + imgfile;
}
Application.ExitThread();
}
The Issue that I am trying to fix is the previous code to generate an image using bitmap with specific width and height.
How I can Make this function work by setting automatic width and height as the given html code, because some times the given html is more than the given dimensional?
Thanks in advance.