【发布时间】:2013-05-25 16:42:57
【问题描述】:
我想一键打印现有的 .pdf 文件。 It works fine when i only print one file at a time, but when choose to print multiple files at once it only prints one file.
这是我的代码:
List<string> ListFilePath; //Assume i have a collection of filepath stored here
foreach(string FilePath in ListFilePath)
{
Process proc = new Process();
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.StartInfo.Verb = "print";
proc.StartInfo.FileName = FilePath;
proc.StartInfo.Arguments = String.Format(@"/p /h {0}", FilePath);
proc.StartInfo.CreateNoWindow = true;
proc.Start();
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
if (proc.HasExited == false)
{
proc.WaitForExit(10000);
}
proc.EnableRaisingEvents = true;
proc.Close();
}
我的错在哪里?
【问题讨论】:
-
它会遍历整个集合吗?它会抛出任何异常吗?在调试器中,你能看到它遍历了所有文件的 process.Start() 行还是第一个文件?
-
是的,它会遍历所有文件的 process.Start()。当我将它定位到 OneNote 时,输出是多个文件。但是当我将它定位到打印机时,它只打印一个文件
-
也许问题更深层 - PrintSpooler 服务。它有多个文档排队的已知问题。
-
好的,我会检查一下。但是从代码方面来说,我并没有做错什么,对吗?