5

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!

Thanks,
Teja.

Tejaswi Yerukalapudi
  • 8,987
  • 12
  • 60
  • 101

4 Answers4

6

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.

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)
        });
    }
}

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);
Rebecca Scott
  • 2,421
  • 2
  • 25
  • 39
  • Ben is absolutely right, you can not get rid of the Adobe window. – Mario The Spoon Apr 01 '11 at 05:05
  • It works great, but the size of the output file in the printer queue is huge, (A 129kb pdf file generates 10mb output in the printer queue). Do you know why this might be happening? I tried playing around with the image quality settings, but doesn't seem right to me. – Tejaswi Yerukalapudi Apr 06 '11 at 19:54
  • Yes, I've had the same problem, it seems to cause a bit of a bottleneck with big queues. I think it's just the way GhostScript works. It converts the PDF to PostScript and sends that to the printer, I think the size blowout happens there. Doesn't seem to be a huge issue as long as you are using a printer on a local network, if you have to print over a VPN (as I have had to with some users) it becomes prohibitive. If you figure out a solution please let me know ;-) – Rebecca Scott Apr 11 '11 at 00:23
  • Excellent solution to this. If you need portability, you can also redistribute with a portable version of Ghostscript (Licence permissing of course http://portableapps.com/apps/utilities/ghostscript_portable – Will Nov 20 '13 at 16:08
3

This may apply only to the computers where I work, or, more broadly, to this version of Adobe (10) on PCs with Windows 7 installed, but I was able to suppress the opening of Acrobat (Pro) each time I printed to .pdf in any other application by doing the following:

Control Panel > (Devices and) Printers > Double click 'Adobe PDF'> Click 'Printer' > 'Printing Preferences' > Uncheck "View Adobe PDF Results" in the 'Adobe PDF Settings' Tab.

Adam
  • 31
  • 1
0

Regarding the solution Adam proposed (switching off the View Adobe PDF Results from control panel) and Serge Belov commented (on how to do it programmatically), in the registry this change affects the ViewPrintOutput value at 4 positions:

Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\Adobe PDF\PrinterDriverData

Computer\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows NT\CurrentVersion\Print\Printers\Adobe PDF\PrinterDriverData

Computer\HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Print\Printers\Adobe PDF\PrinterDriverData

Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Printers\Adobe PDF\PrinterDriverData

However, if you change it from the registry, it doesn't affect the adobe pdf's behaviour, it still shows the resulting pdf after printing

This might be helpful, though https://groups.google.com/g/microsoft.public.access.reports/c/LWphtEVp6UI

yg86
  • 1
  • 2
0

Maybe it is helpful for you to use the "/n" parameter of Adobe Reader. At least your program keeps the focus. But one instance of the reader stays open.

AcroRd32.exe /n /t ...

See: Questions 619158

Community
  • 1
  • 1
Ludwig Wensauer
  • 1,885
  • 3
  • 32
  • 43