C#禁止Adobe Reader窗口从上来试图打印文档时 [英] C# Prevent Adobe Reader Window from coming up when trying to print a document
问题描述
有关原因,我不能进入,现在,我需要防止Adobe Reader窗口的开放,当我尝试打印文档。这是在做这个我之前的开发者以下标志设置,但我真的不知道他们是什么 -
For reasons I can't get into right now, I need to prevent the Adobe Reader window from opening up when I try to print a document. The developer that was working on this before me has the following flags set, although I'm not really sure what they're for -
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();
任何帮助深表感谢!
Any help is much appreciated!
谢谢你,
Teja公司。
Thanks,
Teja.
推荐答案
虽然我不能具体回答你的问题,我发现,我不能这样做与Adobe的版本为9或10,让你不能剿打印对话框中改变了读者,我认为,和窗口本身保持上来,无论如何,既然我的用户都有不同版本的Reader的安装我couldn T得到什么一贯的工作。如果你想尝试反正看看读者的API - 您需要添加到正确的COM库的引用,并从那里走。痛苦的。
While I can't answer your question specifically, I found that I couldn't do this as Adobe changed Reader I think at version 9 or 10 so that you couldn't supress the print dialog, and the window itself kept coming up anyway, and since my users all had different versions of Reader installed I couldn't get anything consistently working. If you want to try anyway have a look at Reader's API - you need to add a reference to the correct COM library and go from there. Painful.
我最终运行通过 GhostScript的的PDF完全下降的Adobe。以下是辅助类我创建做的工作。 gsExePath
应该是类似 C:\Program Files\gs\gs8.71\bin\gswin32c.exe $ C 。$ C>
I ended up dropping Adobe completely by running the PDF through GhostScript. Following is the helper class I created to do the job. gsExePath
should be something like 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默认打印机:
The following should print to the Windows default printer:
var printerName = new System.Drawing.Printing.PrinterSettings().PrinterName;
var gs = new GSInterface(gsExePath);
gs.Print(filename, printername);
这篇关于C#禁止Adobe Reader窗口从上来试图打印文档时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!