views:

331

answers:

1

Hi,

I have been presented with a problem which requires me to print PDF files from a server as part of an ASP.NET web service.

The problem is further complicated by the fact that the PDF files I have to print can ONLY be printed using Adobe Reader (they were created using Adobe LiveCycle and have some strange protection in them).

This piece of code seems to do the trick in the Visual Studio development web server, but doesn't do anything when the site's running in IIS.

I'm assuming this is probably some sort of permissions issue!?

I know this is a FAR from ideal thing to be trying to do, but I haven't really got much choice! Any ideas would be greatly appreciated!

Dim starter As ProcessStartInfo
Dim Prc As Process

' Pass File Path And Arguments 
starter = New ProcessStartInfo("c:\program files\...\AcroRd32.exe", "/t ""test.pdf"" ""Printer""")
starter.CreateNoWindow = True
starter.RedirectStandardOutput = True
starter.UseShellExecute = False

' Start Adobe Process 
Prc = New Process()
Prc.StartInfo = starter
Prc.Start()
+1  A: 

First off yes it probably is a permission issue. Make sure whatever account you have your web app running under has access.

Second be carefull with RedirectStandadoutput. This creates a pipe the child process. If the pipe fills up then the child process blocks on the next attempt to write to console until the pipe is read from by the host. If the host process attempts to sync read from the pipe and no data is present then the host will block. If you really want to redirect standard out make sure you use the async read method BeginOutputReadLine.

// I'm not a vb expert expert in c# you'd do this
StringBuilder builder = new StringBuilder();
prc.BeginOutputReadLine((sender, args) => builder.Append(args.Data));
if (!prc.WaitForExit(timeOut))
{
   prc.Kill();
}
prc.WaitForExit();

If you add a timeout on the prc.WaitForExit make sure to add the kill and the second WaitForExit. WaitForExit with a timeout does not wait for all output to be read from the pipe.

Finally, this isn't going to work for large documents or multiple concurrent requests. By the time the document is spooled to the printer a connection timeout will have occured in the web service.

Why don't you use either use Message Queue or a DB table to store your request and then create an NT service to handle the printing portion of this. In either case the service can poll for messages, print and then then notify the user with an email when printing completes.

csaam