Windows 7 - Problem Printing PDF silently from a Windows Directory watch application

Asked By Confused But Happy on 09-Aug-12 06:16 AM
Hi All

Using Adobe 9 version 9.3.0, Visual studio 2008/C#

I have a wee problem.

Due to the restrictions of printing from (a .net browser application) the b=
rowser I have created a Windows Watch Application to watch a directory (run=
ning it locally at the moment but it will run on the IIS web server).

When a PDF document arrives in the watch folder (created by the .net web ap=
p using iTextSharp) the watch application will pick up the PDF document and=
send it to the chosen printer using the printer value (that will only chan=
ge if there is a problem with the printer) selected from a Combobox in the =
watch application

The problems I am having are

1. The Print Dialogue in Adobe Acrobat always picks up my Default Printer.
2. The print actually does not appear to be going anywhere (not even my def=
ault printer).

What is actually happening is as follows

1. The watch application detects the new pdf file
2. The Print Dialogue appears with my default printer selected and the corr=
ect document previewed.
3. The Print Dialogue disappears (with no intervention from me) and there i=
s no resulting print ??????
4. If I pause the application just before the Kill command I can hit the OK=
button on the print dialogue and it prints to the Default printer (I get 2=
copies for some reason).

The values of the vars are as follows
fullFileName =3D "C:\\Inetpub\\wwwroot\\ZebraBackup\\ZebraBackup\\MyPDFOutp=

selectedPrinter =3D "\\\\dun-server6\\Finance Canon"

strArguments =3D "/t
\" C:\\Inetpub\\wwwroot\\ZebraBackup\\ZebraBackup\\MyPDFOutputs\\S134463.pd=
f\" \"            \\\\dun-server6\\Finance Canon\" "

The Print Dialogue appears with my default printer selected

\\Dun-Server6\HR Printer 3015


Can anyone please assist and tell me where I am going wrong as I feel I am =
going nuts.

Please see my code below

Many thanks in advance for any assistance offered


Iain (confused but happy)

ProcessStartInfo startInfo =3D new ProcessStartInfo("AcroRd32.exe");
string strArguments        =3D "/t \"" + fullFileName + "\" \"" +
selectedPrinter + "\"";

Process proc               =3D new Process();
startInfo.WindowStyle      =3D ProcessWindowStyle.Hidden;
startInfo.FileName         =3D fullFileName;
startInfo.Verb             =3D "print";
startInfo.CreateNoWindow   =3D false;
startInfo.ErrorDialog      =3D true;
startInfo.Arguments        =3D strArguments;
startInfo.UseShellExecute  =3D true;
proc.StartInfo             =3D startInfo;

if (proc.HasExited =3D=3D false)

Tim Sprout replied to Confused But Happy on 13-Aug-12 01:09 PM
For my desktop application, to print pdf's on machines not having the
full version of Adobe Acrobat, but only Adobe Reader, I use PInterop
ShellExecute code based on the following forum post:

I find using the PrintTo verb rather than the Print verb shown in the
above code works better to fit to the pdf pages on the paper.

For machines having the full version of Acrobat I use methods defined in
the Adobe SDK (requires referencing Interop.Acrobat.dll):

CAcroAVDoc avDoc = new AcroAVDocClass();
avDoc.Open("file.pdf", "");
avDoc.PrintPagesSilent(0, 0, 0, 0, 1);

I had inconsistent success using command line switches like /t.

I was never able to find a way to change default printer properties from
within C Sharp.

I am able to change default printers, however, from within C Sharp using
the PInterop method SetDefaultPrinter.

-Tim Sprout