[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework

Problems Background Printing PDF from C# Application

lmttag

4/22/2008 12:47:00 AM

Hello,

We are having a lot of problems trying to print a PDF file in the background
using a C# application that is executed via SQL Server Agent. The output
should be printed to a local printer (HP Color LaserJet 1600) connected via a
USB port.

We have a C# application that calls System.Diagnostics.Process to run
Acrobat Reader (weâ??ve tried both v8.0.0 and v8.1.2), open an existing PDF
file, and send it to the local printer. The code is shown below.

System.Diagnostics.Process process = new System.Diagnostics.Process();
process.Refresh();
process.StartInfo.Arguments = "/t C:\Temp\TestPDF.pdf"; // and tried "/t
C:\Temp\TestPDF.pdf PrinterName"
process.StartInfo.CreateNoWindow = false;
//process.StartInfo.Domain;
//process.StartInfo.ErrorDialog = false;
process.StartInfo.FileName = "C:\\Program Files\\Adobe\\Reader
8.0\\Reader\\AcroRd32.exe";
//process.StartInfo.Password;
//process.StartInfo.UserName;
process.StartInfo.UseShellExecute = false;
//process.StartInfo.Verb = "Print";
process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
process.StartInfo.WorkingDirectory = new
System.IO.FileInfo(m_PDFPathFile).DirectoryName;
process.Start();

Weâ??ve tried just about every combination of the process objects properties
trying to get the PDF file to print. But, it never works. The code executes
without error, just nothing ever shows up on the printer.

More infoâ?¦ Weâ??re executing our custom C# application via a SQL Server Agent
job. SQL Server Agent is running as Local System account. The Job Step Type
is Operating System (CmdExec), with Run as set to SQL Server Agent Account.
The command is simply the path and file name of our custom C# application
(e.g., C:\Temp\PrintPDF.exe).

Again, we get no errors/exception and no job failures, but the PDF never
gets printed.

How can we re-code or fix our situation?
What can be done/tried?

All help is appreciated. We are stuck.

Thanks.


1 Answer

Cowboy

4/22/2008 1:15:00 PM

0

I would try to tackle this through the objects rather than wrap the EXE in a
process object. Something like this post:
http://weblogs.asp.net/jgaylord/archive/2006/05/19/4...

Admitedly, in VB, but it is fairly easy to translate to C#.

As for your process, it appears you are missing some arguments to have it
print to a printer:
http://support.adobe.com/devsup/devsup.nsf/docs...

Try supplying all of the necessary arguments and see if that pulls you out
of the fire.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://gregorybeamer.spaces...list...

or just read it:
http://gregorybeamer.spaces...

*************************************************
| Think outside the box!
|
*************************************************
"lmttag" <lmttag@discussions.microsoft.com> wrote in message
news:FA8BDEB5-D9E0-4201-A176-AE5C85D24E82@microsoft.com...
> Hello,
>
> We are having a lot of problems trying to print a PDF file in the
> background
> using a C# application that is executed via SQL Server Agent. The output
> should be printed to a local printer (HP Color LaserJet 1600) connected
> via a
> USB port.
>
> We have a C# application that calls System.Diagnostics.Process to run
> Acrobat Reader (we've tried both v8.0.0 and v8.1.2), open an existing PDF
> file, and send it to the local printer. The code is shown below.
>
> System.Diagnostics.Process process = new System.Diagnostics.Process();
> process.Refresh();
> process.StartInfo.Arguments = "/t C:\Temp\TestPDF.pdf"; // and tried "/t
> C:\Temp\TestPDF.pdf PrinterName"
> process.StartInfo.CreateNoWindow = false;
> //process.StartInfo.Domain;
> //process.StartInfo.ErrorDialog = false;
> process.StartInfo.FileName = "C:\\Program Files\\Adobe\\Reader
> 8.0\\Reader\\AcroRd32.exe";
> //process.StartInfo.Password;
> //process.StartInfo.UserName;
> process.StartInfo.UseShellExecute = false;
> //process.StartInfo.Verb = "Print";
> process.StartInfo.WindowStyle =
> System.Diagnostics.ProcessWindowStyle.Hidden;
> process.StartInfo.WorkingDirectory = new
> System.IO.FileInfo(m_PDFPathFile).DirectoryName;
> process.Start();
>
> We've tried just about every combination of the process objects properties
> trying to get the PDF file to print. But, it never works. The code
> executes
> without error, just nothing ever shows up on the printer.
>
> More info. We're executing our custom C# application via a SQL Server
> Agent
> job. SQL Server Agent is running as Local System account. The Job Step
> Type
> is Operating System (CmdExec), with Run as set to SQL Server Agent
> Account.
> The command is simply the path and file name of our custom C# application
> (e.g., C:\Temp\PrintPDF.exe).
>
> Again, we get no errors/exception and no job failures, but the PDF never
> gets printed.
>
> How can we re-code or fix our situation?
> What can be done/tried?
>
> All help is appreciated. We are stuck.
>
> Thanks.
>
>