Server side PDF printing with Acrobat Reader from ASP.NET

I was presented with a problem that requires me to print PDF files from the server as part of an ASP.NET web service.

The problem is compounded by the fact that the PDFs I have to print can ONLY be printed with Adobe Reader (they were created using Adobe LiveCycle and have some weird security in them).

This piece of code seems to do the trick on the Visual Studio development web server, but does nothing when the site is running on IIS.

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

I know this is FAR from the perfect thing to try and do, but I really don't have 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()

      

+2


a source to share


1 answer


First of all, yes, it might be a permission issue. Make sure that whatever account your web application is running has access.

Second, be careful with RedirectStandadoutput. This creates a channel for the child process. If the pipe fills up, then the child process blocks the next attempt to write to the console until the pipe is read by the host. If the host process tries to synchronize a read from the pipe and there is no data, the host blocks. If you really want to redirect the standard version, make sure you use the async BeginOutputReadLine read method.

// 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 to prc.WaitForExit, be sure to add kill and a second WaitForExit. WaitForExit with a timeout does not wait for all output to be read from the pipe.

Finally, this will not work for large documents or multiple concurrent requests. By the time the document is launched to the printer, the connection timed out in the web service.

Why not use either a Message Queuing or a DB table to store your query, and then create an NT service to handle that part of the print. In either case, the service can poll the messages, print, and then notify the user via email when the print is complete.

+3


a source







All Articles