PC Review


Reply
Thread Tools Rate Thread

Problem Printing PDF silently from a Windows Directory watch application

 
 
Confused But Happy
Guest
Posts: n/a
 
      9th Aug 2012
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();
}
 
Reply With Quote
 
 
 
 
Tim Sprout
Guest
Posts: n/a
 
      13th Aug 2012
On 8/9/2012 2:16 AM, Confused But Happy wrote:
> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem Printing PDF silently from a Windows Directory watch application Confused But Happy Microsoft Dot NET 0 9th Aug 2012 10:52 AM
Deployment of NET 2.0 application - installing silently Toma Catalin Microsoft Dot NET Framework 4 11th Jul 2008 01:39 PM
SyncToy failing silently because of long path name (& relatedWindowsFormsParkingWindow shutdown problem) prepbgg@googlemail.com Windows XP General 0 27th Jun 2008 12:33 PM
Application unexpectedly quits silently vachesacree@yahoo.com Microsoft Dot NET Compact Framework 7 22nd Mar 2006 03:23 PM
VBA code silently crashing. Problem with Data Validation drop down lists. Don Wiss Microsoft Excel Programming 6 27th Feb 2005 10:46 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:34 PM.