?
Solved

Shell Execute Print

Posted on 2003-11-26
6
Medium Priority
?
2,070 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 1500 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…
Suggested Courses
Course of the Month11 days, 17 hours left to enroll

752 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