Solved

Shell Execute Print

Posted on 2003-11-26
6
2,027 Views
Last Modified: 2013-12-26
Hi,

I'm trying to print a PDF document from VB.

I tried : myProcessID = Shell(all, 0) but I don't know WHEN to kill the process since I don't know if the print is done.

I tried ShellExecute(hwnd, "Print", file, flags, "", 0) but I don't know WHAT process to kill


I'm using Acrobat 6.0 and after the printing is done, the application Acrobat is still in my process list, but I would want it to die.


What should i do ?

thanks in advance
0
Comment
Question by:pchaloux
6 Comments
 
LVL 27

Expert Comment

by:Dabas
ID: 9828999
Hi pchaloux,
Instead of using Shell, I would try to use a reference or a component that allows you to do the printing through COM

Dabas
0
 
LVL 1

Expert Comment

by:vbs03
ID: 9830406
Hi
The approach that u have taken is perfect.
 myProcessID = Shell(all, 0)

Now since the printing process is asynchronous with ur execution. We need not be aware of whether printing is complete.
Due to ur Shell command the Acorobat EXE is launched and the printing starts. After that in ur program just say:
ExitProcess myProcessID

This is an API call.  myProcessID will contain the process ID of the Acrobat and hence it will terminate the Reader.

If u require to capture the status of the printing process then this approach is not suitable. Because here we are getting the status whether the Acrobat EXE has launched successfully or not.

Regards,
VBS
0
 
LVL 7

Accepted Solution

by:
wsteegmans earned 500 total points
ID: 9831203
Hi pchaloux,

Normally, if you use ShellExecute for printing documents, the application will close after the print-job (check it out with for example Microsoft Word).

However, Acrobat Reader is a little bit different.

You could use ShellExecuteEx and WaitForSingleObject. ShellExecuteEx gives you the ProcessID, and with WaitForSingelObject, you can wait until the Print-Job is done.

However, like I already said, Acrobat Reader is just a bit different, because it does not send the message that it's completed. So, we can't us the WaitForSingelObject because it will wait forever ... That's why ShellExecute also doesn't close Acrobat Reader (I think).

Another API is WaitForInputIdle. WaitForInputIdle waits untill the starting process is initialized, and is ready to receive input. But the application is ready, and then starts to print. So, if we kill it when the WaitForInputIdle is True, we kill it before we printed it ...

But, no APIs anymore, we can also use the PDF.OCX control.

In Visual Studio, go to your components, and browse to something like
C:\Program Files\Adobe\Acrobat 5.0\Reader\ActiveX\pdf.ocx

Drag the new OCX control to your form. You can resize it, or you can also set it to Visible = False (so the user doesn't see the document).

The component is given the default name of PDF1, so you would simply write first the open statement:

      Pdf1.LoadFile ("C:\Folder\FileName.pdf")

Then, you can print it (a lot of possibilities ...)

      Pdf1.Print      
      Pdf1.printAll
      Pdf1.printAllFit
      Pdf1.printPages 1, 5
      Pdf1.printPagesFit 1, 5, True
      Pdf1.printWithDialog

Hope this helps ..
Regards!
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:pchaloux
ID: 9859224
Hi there,

We (my collegues and I) already tried what you suggested, and nothing worked.

I think it's a bug in Acrobat Reader 6.0 because my collegues who have acrobat 5.0 don't have any problem with he solution you gave.
0
 
LVL 7

Expert Comment

by:wsteegmans
ID: 9865622
Hi,

I think there's something wrong with your Acrobat Reader installation. I tested it with VB6 SP5, both with Acrobat 5.0 and Acrobat 6.0, and it just works fine !?

Regards!
0
 
LVL 7

Expert Comment

by:wsteegmans
ID: 9874925
Does it work now with Acrobat 6.0? Did you find the problem?

Regards!
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now