C # Prevent Adobe Reader from appearing when trying to print a document

For reasons that I cannot get into right now, I need to prevent the Adobe Reader window from opening when I try to print a document. The developer who worked on this in front of me has the following flags, although I'm not sure what they are 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!

Thanks,
Thea

+4
source share
3 answers

While I cannot answer your question specifically, I found that I could not do this because Adobe changed Reader, I think in version 9 or 10, so that you could not suppress the print dialog, and the window itself continued in any case, and since my users had different versions of Reader, I couldn’t get anything to work consistently. If you want to try looking at the Reader API anyway, you need to add a link to the correct COM library and go from there. Painful.

In the end, I completely dropped Adobe by running the GhostScript PDF file. The following is a helper class that I created to do this 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) }); } } 

The following should be printed on the default Windows printer:

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

This can only apply to the computers I work on, or, more broadly, to this version of Adobe (10) on a PC with Windows 7 installed, but I was able to suppress the opening of Acrobat (Pro) every time I print to .pdf in any other application by following these steps:

Control Panel> (Devices and) Printers> Double-click "Adobe PDF"> Click "Printer"> "Print Settings"> Uncheck "View Adobe PDF Results" on the "Adobe PDF Settings" tab.

+2
source

You might find it helpful to use the "/ n" option for Adobe Reader. At least your program keeps focus. But one copy of the reader remains open.

 AcroRd32.exe /n /t ... 

See: Questions 619158

+1
source

Source: https://habr.com/ru/post/1346164/


All Articles