当尝试使用'ProcessStartInfo‘和'printto’动词打印word文档时,会向用户显示来自MS的消息框,用于显示每个打印的文档,说明“存在打印机错误”。该文档仍然成功打印,但这对该应用程序的用户处理时间有很大的影响。
错误消息:误字信息
下面是我打印文档的当前代码:
private static void PrintDocument(string document)
{
if (!String.IsNullOrEmpty(printerName))
{
ProcessStartInfo info = new ProcessStartInfo(document);
info.Verb = "PrintTo";
info.Arguments = printerName;
info.CreateNoWindow = true;
info.WindowStyle = ProcessWindowStyle.Hidden;
Process.Start(info);
}
else
{
PrintDialog pd = new PrintDialog();
if (pd.ShowDialog() == DialogResult.OK)
{
printerName = pd.PrinterSettings.PrinterName;
PrintDocument(document);
}
}
}有人能给我建议吗?
发布于 2022-02-01 12:25:54
我看到您的打印文档函数是static。我认为问题可能是你开始了这个过程,让它挂起,然后再调用它。尝试:
Process.Start(info);
Process.WaitForExit();
var exitCode = Process.ExitCode; //useful to handle errors发布于 2022-02-01 22:54:33
当您通过向文档传递路径来启动新进程时,将为此启动默认编辑器。所以,你不能确定Word总是在处理这样的任务。所以,我建议用自动化的词代替。Document.PrintOut方法打印指定文档的全部或部分。在调用默认打印机之前,可以在C#中配置它。
https://stackoverflow.com/questions/70940029
复制相似问题