Solved

Shell Execute Print

Posted on 2003-11-26
6
2,033 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

914 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

16 Experts available now in Live!

Get 1:1 Help Now