虽然我无法具体回答你的问题,但我发现我无法做到这一点,因为 Adobe 在版本 9 或 10 中更改了 Reader,这样你就无法抑制打印对话框,而且窗口本身仍然不断出现,由于我的用户都安装了不同版本的 Reader,因此我无法让任何内容始终如一地工作。如果您想尝试,请查看 Reader 的 API - 您需要添加对正确 COM 库的引用,然后从那里开始。痛苦。
我最终通过运行 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);