I'm working on a print app that needs to print the images sequentially. The list has tif images and xml formatted documents. I'm using WebBrowser to navigate to the xml and after DocumentComplete I call WebBrowser.Print() to start printing.
The problem is that WebBrowser doesn't starting print immediately. It looks like it's sporadic when WebBrowser actually wants to print.
Here is the code that is similar how my code looks like.
Anyone know what triggers the printing to start or away work around it?
public partial class Form1 : Form
{
private WebBrowser _webBrowser1 = new WebBrowser();
private List<string> _list = new List<string>();
public Form1()
{
InitializeComponent();
this._webBrowser1.Name = "webBrowser1";
this._webBrowser1.DocumentCompleted += new System.Windows.Forms.WebBrowserDocumentCompletedEventHandler(this.webBrowser1_DocumentCompleted);
this._list.Add("test1.tif");
this._list.Add("http://bing.com");
this._list.Add("test2.tif");
this._list.Add("test3.tif");
}
private void button1_Click(object sender, EventArgs e)
{
this.StartPrinting();
}
private void StartPrinting()
{
if (this._list.Count == 0)
return;
string imgPath = this._list[0];
this._list.RemoveAt(0);
if (imgPath.EndsWith(".tif") == true)
{
// Code to print tif
System.Threading.Thread.Sleep(3000);
// Print Next Image
this.StartPrinting();
}
else
{
// ex. http://test.com/mytest.xml
this._webBrowser1.Navigate(imgPath);
}
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
// THIS IS THE PROBLEM, it doesn't show the prompt until later in the loop
this._webBrowser1.ShowPrintDialog();
// Print Next Image
this.StartPrinting();
}
}