0
我正在尝试将HTML报告批量打印到我的默认打印机,该打印机是用于自动保存的PDF Creator设置。我已经通过Internet Explorer加载了HTML文件,并从那里打印出来,而无需用户提示。大容量打印HTML问题假脱机文件
我遇到的问题是,当我的程序循环打印HTML文件列表时,它发现一些文档不能打印并且不打印。我在网上读过,可以使用while循环和Application.Dowork()来解决这个问题。当我偶尔执行这些操作时,我的所有文档都会打印出来,这是一个很大的改进,但这只是偶尔而不是确定的。
我的问题可能是每个线程在完成处理之前关闭吗?
如果是这样,我怎么能让线程独立运行,以便它们在处理过程中不会关闭?
下面是我用来打印文档的默认打印机代码:
foreach (var x in fileList)
{
// Printing files through IE on default printer.
Console.WriteLine("{0}", x);
SHDocVw.InternetExplorer IE = new SHDocVw.InternetExplorer();
IE.DocumentComplete += new SHDocVw.DWebBrowserEvents2_DocumentCompleteEventHandler(IE_DocumentComplete);
IE.PrintTemplateTeardown += new SHDocVw.DWebBrowserEvents2_PrintTemplateTeardownEventHandler(IE_PrintTemplateTeardown);
IE.Visible = true;
IE.Navigate2(x);
while (IE.ReadyState != SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE)
{
System.Windows.Forms.Application.DoEvents();
}
}
}
}
}
static void IE_PrintTemplateTeardown(object pDisp)
{
if (pDisp is SHDocVw.InternetExplorer)
{
SHDocVw.InternetExplorer IE = (SHDocVw.InternetExplorer)pDisp;
IE.Quit();
System.Environment.Exit(0);
}
}
static void IE_DocumentComplete(object pDisp, ref object URL)
{
if (pDisp is SHDocVw.InternetExplorer)
{
SHDocVw.InternetExplorer IE = (SHDocVw.InternetExplorer)pDisp;
IE.ExecWB(SHDocVw.OLECMDID.OLECMDID_PRINT, SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER, 2);
}
}