Tej*_*udi 5 c# printing 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();
Run Code Online (Sandbox Code Playgroud)
任何帮助深表感谢!
谢谢,
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)
});
}
}
Run Code Online (Sandbox Code Playgroud)
以下应打印到Windows默认打印机:
var printerName = new System.Drawing.Printing.PrinterSettings().PrinterName;
var gs = new GSInterface(gsExePath);
gs.Print(filename, printername);
Run Code Online (Sandbox Code Playgroud)