Problem Printing PDF silently from a Windows Directory watch application

  • Thread starter Confused But Happy
  • Start date
C

Confused But Happy

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 browser I have created a Windows Watch Application to watch a directory (running 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 app using iTextSharp) the watch application will pick up the PDF document andsend it to the chosen printer using the printer value (that will only change 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 default 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 correct document previewed.
3. The Print Dialogue disappears (with no intervention from me) and there is no resulting print ??????
4. If I pause the application just before the Kill command I can hit the OKbutton on the print dialogue and it prints to the Default printer (I get 2copies for some reason).


The values of the vars are as follows
fullFileName = "C:\\Inetpub\\wwwroot\\ZebraBackup\\ZebraBackup\\MyPDFOutputs\\S134463.pdf"

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

strArguments = "/t
\" C:\\Inetpub\\wwwroot\\ZebraBackup\\ZebraBackup\\MyPDFOutputs\\S134463.pdf\" \" \\\\dun-server6\\Finance Canon\" "

The Print Dialogue appears with my default printer selected

\\Dun-Server6\HR Printer 3015

"\\\\dun-server6\\Finance Canon\" this is the selected printer from the combobox



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

Regards

Iain (confused but happy)


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

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

proc.WaitForExit(5000);
if (proc.HasExited == false)
{
proc.Kill();
}
 
T

Tim Sprout

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 browser I have created a Windows Watch Application to watch a directory (running 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 app 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 change 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 default 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 correct document previewed.
3. The Print Dialogue disappears (with no intervention from me) and there is 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 = "C:\\Inetpub\\wwwroot\\ZebraBackup\\ZebraBackup\\MyPDFOutputs\\S134463.pdf"

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

strArguments = "/t
\" C:\\Inetpub\\wwwroot\\ZebraBackup\\ZebraBackup\\MyPDFOutputs\\S134463.pdf\" \" \\\\dun-server6\\Finance Canon\" "

The Print Dialogue appears with my default printer selected

\\Dun-Server6\HR Printer 3015

"\\\\dun-server6\\Finance Canon\" this is the selected printer from the combobox



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

Regards

Iain (confused but happy)


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

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

proc.WaitForExit(5000);
if (proc.HasExited == false)
{
proc.Kill();
}

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:

<http://social.msdn.microsoft.com/Forums/zh/winforms/thread/383a91d3-7bc1-4ef2-b32e-71e75e794f1c>

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);
avDoc.Close(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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top