我需要从硬盘驱动器打印多个PDF文件 . 我发现了如何将文件发送到打印机的美丽solution . 此解决方案的问题在于,如果要打印多个文件,则必须等待每个文件以完成该过程 .
在命令shell中,可以使用具有多个文件名的相同命令: print /D:printerName file1.pdf file2.pdf
并且一次调用将全部打印出来 .
不幸的是,只是将所有文件名放入 ProcessStartInfo
不起作用
string filenames = @"file1.pdf file2.pdf file3.pdf"
ProcessStartInfo info = new ProcessStartInfo();
info.Verb = "print";
info.FileName = filenames;
也不把文件名设为 Arguments
Process
info.Arguments = filename;
我总是得到错误:找不到文件!
如何通过一个进程调用打印多个文件?
以下是我现在如何使用它的示例:
public void printWithPrinter(string filename, string printerName)
{
var procInfo = new ProcessStartInfo();
// the file name is a string of multiple filenames separated by space
procInfo.FileName = filename;
procInfo.Verb = "printto";
procInfo.WindowStyle = ProcessWindowStyle.Hidden;
procInfo.CreateNoWindow = true;
// select the printer
procInfo.Arguments = "\"" + printerName + "\"";
// doesn't work
//procInfo.Arguments = "\"" + printerName + "\"" + " " + filename;
Process p = new Process();
p.StartInfo = procInfo;
p.Start();
p.WaitForInputIdle();
//Thread.Sleep(3000;)
if (!p.CloseMainWindow()) p.Kill();
}
2 回答
以下应该工作:
它不一定是一个简单的解决方案,但您可以先合并pdf然后再发送给acrobat .
例如,使用PdfMerge
初始方法的示例重载: