Solved

Shell Execute Print

Posted on 2003-11-26
6
2,062 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

729 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