Problems Background Printing PDF from C# Application

L

lmttag

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.
 
C

Cowboy \(Gregory A. Beamer\)

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/447379.aspx

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/52080.htm

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.live.com/lists/feed.rss

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

*************************************************
| Think outside the box!
|
*************************************************
 

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