Solved

Shell Execute Print

Posted on 2003-11-26
6
2,052 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
Technology Partners: 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
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…

733 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