C#在尝试打印文档时阻止Adobe Reader窗口出现

由于我无法立即进入的原因,我需要在尝试打印文档时阻止Adobe Reader窗口打开。 在我之前处理这个问题的开发人员设置了以下标志,虽然我不确定他们是为了什么 –

if (RegistryManager.GetAcrobatVersion() >= 9.0f) printerArg = "\"" + printerName + "\""; else printerArg = printerName; Process myProc = new Process(); myProc.StartInfo.FileName = fileName; myProc.StartInfo.Verb = "printto"; myProc.StartInfo.UseShellExecute = true; myProc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; myProc.StartInfo.CreateNoWindow = true; myProc.StartInfo.Arguments = "\"" + printerName + "\""; bool result = myProc.Start(); if (myProc.WaitForInputIdle()) { if (!myProc.HasExited) { myProc.WaitForExit(Convert.ToInt32(5000)); myProc.Kill(); } } myProc.Close(); 

任何帮助深表感谢!

谢谢,
Teja公司。

虽然我无法专门回答你的问题,但我发现我无法做到这一点,因为Adobe更改了我认为在版本9或10版本中,因此您无法抑制打印对话框,并且窗口本身无论如何都会出现,因为我的用户都安装了不同版本的Reader,所以我无法持续工作。 如果你想尝试一下看看Reader的API – 你需要添加对正确的COM库的引用并从那里开始。 痛苦。

我最终通过GhostScript运行PDF来完全放弃Adobe。 以下是我为完成这项工作而创建的助手类。 gsExePath应该类似于C:\Program Files\gs\gs8.71\bin\gswin32c.exe

 public class GSInterface { public string GhostScriptExePath { get; private set; } public GSInterface(string gsExePath) { this.GhostScriptExePath = gsExePath; } public virtual void CallGhostScript(string[] args) { var p = new Process(); p.StartInfo.FileName = this.GhostScriptExePath; p.StartInfo.Arguments = string.Join(" ", args); p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; p.Start(); p.WaitForExit(); } public void Print(string filename, string printerName) { this.CallGhostScript(new string[] { "-q", "-sDEVICE=mswinpr2", "-sPAPERSIZE=a4", "-dNOPAUSE", "-dNoCancel", "-dBATCH", "-dDuplex", string.Format(@"-sOutputFile=""\\spool\{0}""", printerName), string.Format(@"""{0}""", filename) }); } } 

以下应打印到Windows默认打印机:

 var printerName = new System.Drawing.Printing.PrinterSettings().PrinterName; var gs = new GSInterface(gsExePath); gs.Print(filename, printername); 

这可能仅适用于我工作的计算机,或者更广泛地适用于安装了Windows 7的PC上的此版本的Adobe(10),但每次打印时我都能够禁止打开Acrobat(Pro)。 pdf在任何其他应用程序中执行以下操作:

控制面板>(设备和)打印机>双击“Adobe PDF”>单击“打印机”>“打印首选项”>在“Adobe PDF设置”选项卡中取消选中“查看Adobe PDF结果”。

也许使用Adobe Reader的“/ n”参数很有帮助。 至少你的程序保持焦点。 但是读者的一个例子保持开放。

 AcroRd32.exe /n /t ... 

见: 问题619158