5

I am launching Reader 10.0 to send a PDF file to a printer from a C# program on a Win 7 system. Here's what I am doing now:

startInfo.FileName = adobeReaderPath;
string args = String.Format("/t \"{0}\" \"{1}\"", this.pdfFileName, this.printerName);
startInfo.Arguments = args;
startInfo.CreateNoWindow = true;
startInfo.ErrorDialog = false;
startInfo.UseShellExecute = false;
startInfo.WindowStyle = ProcessWindowStyle.Minimized;
Process process = Process.Start(startInfo);

I noticed that launching Reader like this (or from command prompt) actually starts 2 AcroRd32.exe executables. Neither of them is minimized. I also tried ProcessWindowStyle.Hidden with the same result.

Is there a way of forcing Reader to start minimized?

Thanks!

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
I Z
  • 5,719
  • 19
  • 53
  • 100
  • Could you post a more complete sample(Like how you call this function and from here) Because I recently did the same thing on Win 7 and had only 1 instance running. – Alex Mar 09 '12 at 14:13

5 Answers5

2

Try it with inclduding /h in your command line. This launches an Adobe Reader instance minimized to the taskbar. There is however no "nice" option to hide it completly (To my knowledge). Other than hack some unpredictable stuff with the Win32 API. The more generic approach to start some app minimized is over the API. See Steve's post.

This should do:

string args = String.Format("/h /t \"{0}\" \"{1}\"", this.pdfFileName, this.printerName);
Alex
  • 7,901
  • 1
  • 41
  • 56
2

After launching the process, you can get the MainWindowHandle of it and use P/Invoke to minimize it:

[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

//..
ShowWindow(process.MainWindowHandle, 11);  //11 is ForceMinimized
Steve Danner
  • 21,818
  • 7
  • 41
  • 51
  • 1
    Why would you use the Win32 API when there is a built in function of Adobe to start it minimized :)? – Alex Mar 08 '12 at 14:56
  • @Alex, if he ever wants this to be more generic, the Win32 API is the way to go. Certainly the parameter will work for Adobe, but what if he needs it to work with FoxIt, or some other app? – Steve Danner Mar 08 '12 at 15:01
  • @Steve, I tried it but this seems to have no effect on the Reader window, i.e. after the call to ShowWindow the window is still not minimized – I Z Mar 08 '12 at 15:33
  • You might want to try one of the other nCmdShow parameters in the pInvoke link. You might try 2 (ShowMinimized) or 0 (Hide) – Steve Danner Mar 08 '12 at 16:29
  • Unfortunately, same result. :( It probably has something to do with the fact that Acrobat somehow launches two AcroRd32 processes when the process is started. – I Z Mar 08 '12 at 22:29
  • That is odd. Sounds like how the web browsers handle multiple tabs. Perhaps try iterating through all of the child processes as well and calling the same win32 methods on them. – Steve Danner Mar 09 '12 at 13:32
0
Process proc = new Process();
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.StartInfo.Verb = "print";

proc.StartInfo.FileName = @"Path of Adobe exe";
proc.StartInfo.Arguments = String.Format(@"/p /h {0}", fileToPrint);
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;
proc.Start();
kkyr
  • 3,785
  • 3
  • 29
  • 59
ZEG
  • 1
0

See this: http://www.robvanderwoude.com/commandlineswitches.php#Acrobat

Open a PDF file:

AcroRd32.exe PdfFile

Open a PDF file in a new instance of Adobe Reader:

AcroRd32.exe /N PdfFile

Open a PDF file at page 7:

AcroRd32.exe /A "page=7=OpenActions" PdfFile

Open a PDF file with navigation pane active, zoom out to 50%, and search for and highlight the word "batch":

AcroRd32.exe /A "zoom=50&navpanes=1=OpenActions&search=batch" PdfFile

Print a PDF file with dialog:

AcroRd32.exe /P PdfFile

Print a PDF file silently:

AcroRd32.exe /N /T PdfFile PrinterName [ PrinterDriver [ PrinterPort ] ]

The last command will open a new Adobe Reader window, print the PDF file and then terminate its window unless that window happens to be the only Adobe Reader window left: at least one Adobe Reader window will be left open.

Edit: http://partners.adobe.com/public/developer/en/acrobat/PDFOpenParameters.pdf#page=5

Zelter Ady
  • 6,266
  • 12
  • 48
  • 75
0

You actually cannot send a pdf document directly to printer using Adobe acrobat reader using the code you have mentioned.

What you need is a .net pdf api which has the functionality implemented to print pdf. you can add reference to the project and then start using the api. you can google/bing on internet about souch apis which are also free and easy to use.

Uday0119
  • 770
  • 1
  • 7
  • 23
  • I am doing it quite successfully. The only issue is the annoying Reader window that pops up and that I am trying to minimize. – I Z Mar 08 '12 at 15:34
  • Ok, Since AcroRd32.exe keeps running after the printing is over, you can use Process class to get running processes by name of AcroRd32.exe using Process.GetProcessesByName("AcroRd32.exe") and kill them by calling Kill method of Process class instance. Remember, Process.GetProcessesByName method gives you an array of Process instances, so you need to loop over and kill the process by calling Kill method – Uday0119 Mar 08 '12 at 16:02
  • I am doing this already too. I am just trying to avoid the pop up window when the process gets launched – I Z Mar 08 '12 at 16:10
  • Ok, but i recommend u to use pdf .net api to use, as they are more convinient to use than using adobe reader. Some Apis does not even require you to have adobe reader installd on ur pc and they are fast too... – Uday0119 Mar 08 '12 at 17:10
  • UDAY, do you have a specific API in mind which would happen to have its source code also available? – I Z Mar 09 '12 at 14:25
  • Well, i dont have much hands-on on PDF library using .net but some popular libraries are iText, PDFLib... etc... you can get list [here](http://csharp-source.net/open-source/pdf-libraries) also... – Uday0119 Mar 10 '12 at 05:51