Close Window Command or Monitor Print Queue?

B

brogdon

I'm attempting to build an ASP.NET (VB) application that will do
server-side printing of PDF files. I have used a Process object to
launch Adobe's AcroRd32 program with the /t switch which causes it to
open an Acrobat Reader window and silently send the document I want
printed to a local network printer:

Dim psiInfo As ProcessStartInfo = New ProcessStartInfo
(pathtoadobe, "/t " + filename + " " + printername)

psiInfo.CreateNoWindow = True
psiInfo.UseShellExecute = True

Dim procPrint As Process = New Process()
procPrint.StartInfo = psiInfo
procPrint.Start()

This works nicely except for the fact that after it finishes printing,
the Acrobat window stays open on the server. I had thought the /t
switch would cause it to close when it was finished, but I was
apparently wrong. This is unacceptable, because after ten print runs
on the server, I'll end up with ten open acrobat windows!

How can I deal with this problem? It's a simple matter to kill the
process, but how do I know when it's done sending the job to the
printer? If I kill it too early, I could lose pages or corrupt the job
or worse. Is there any way to send something like a WM_COMMAND to the
Adobe window (if I can manage to get a handle to it)? Is there any way
for my to look at the printer's print queue within my ASP.NET code (if
I can do that, I can just check to see if the queue is empty, at which
point I'd know I can kill the process)?
 
H

Harimwakairi

Just in case someone else has a similar issue someday, I thought I'd
post the solution I ended up finding.

It's easier to monitor the print queue. Basically you import two Win32
API calls (see pinvoke.net's winspool section for help on that). The
two you need are OpenPrinter and EnumJobs. Once that's done, it's a
simple matter to check the printer to see how many jobs are running on
it, and kill the Adobe process at the appropriate time.
 

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

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top