C# 一次单击即可打印多个PDF文件
我想一键打印现有的.pdf文件。 当我一次只打印一个文件时,它工作正常,但当选择一次打印多个文件时,它只打印一个文件 这是我的密码:C# 一次单击即可打印多个PDF文件,c#,asp.net,pdf,printing,C#,Asp.net,Pdf,Printing,我想一键打印现有的.pdf文件。 当我一次只打印一个文件时,它工作正常,但当选择一次打印多个文件时,它只打印一个文件 这是我的密码: List<string> ListFilePath; //Assume i have a collection of filepath stored here foreach(string FilePath in ListFilePath) { Process proc = new Process(); proc.StartInfo.W
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();
}
列表ListFilePath//假设我在这里存储了一个filepath集合
foreach(ListFilePath中的字符串文件路径)
{
Process proc=新流程();
proc.StartInfo.WindowStyle=ProcessWindowStyle.Hidden;
proc.StartInfo.Verb=“打印”;
proc.StartInfo.FileName=文件路径;
proc.StartInfo.Arguments=String.Format(@“/p/h{0}”,文件路径);
proc.StartInfo.CreateNoWindow=true;
proc.Start();
proc.StartInfo.WindowStyle=ProcessWindowStyle.Hidden;
如果(proc.HasExited==false)
{
WaitForExit程序(10000);
}
proc.EnableRaisingEvents=true;
过程关闭();
}
我的错误在哪里?您能分配给事件处理程序,然后停止进程吗
不在此方法内。您的代码正在启动进程并在服务器上创建打印作业。你确定这是对的,而且它不应该在客户端上打印吗
您可以尝试将所有pdf合并为一个()文件,然后只打印合并后的pdf文件。这对我来说非常有用
foreach (string pdf in ListFilePath)
{
string filename = System.IO.Path.GetFileName(pdf);
string fullPath = (@"U:\Define\Full\Path" + filename);
Print(fullPath, 'PrinterNameHere');
}
public static bool Print(string file, string printer)
{
try
{
Process.Start(Registry.LocalMachine.OpenSubKey(
@"SOFTWARE\Microsoft\Windows\CurrentVersion" +
@"\App Paths\AcroRd32.exe").GetValue("").ToString(),
string.Format("/h /t \"{0}\" \"{1}\"", file, printer));
return true;
}
catch
{ return false; }
}
你的意思是我必须停止循环之外的过程?对。当流程告诉您,它已经准备好了。这是一个建议。在事件中选中此项。它是否遍历整个集合?它会抛出异常吗?在调试器中,您能看到它在所有文件的process.Start()行中运行还是在第一行中运行?是的,它在所有文件的process.Start()中运行。当我将其定向到OneNote时,输出是多个文件。但当我把它定位到打印机上时,它只打印一个文件——也许问题更严重——PrintSpooler服务。它知道在排队处理多个文档时存在问题。好的,我来检查一下。但从代码方面看,我没有做错什么,对吗?