Solved

Closing the Adobe Acrobat program in an application

Posted on 2003-11-13
11
1,000 Views
Last Modified: 2013-12-03
I have an application which looks to a certain directory to see if a request has been made to print some pdf files.  We are using Adobe Acrobat program to get the pdf file from a designated location. After the application has printed all the pdf files, the application goes to sleep for 10 minutes than goes out and checks if another request has been submitted, the scenario starts over again, gets the pdf file and prints it, than after all requests are completed, goes to sleep for 10 minutes.  The problem I am having is that the Adobe Acrobat program does not close when we are finished.  Because I am printing in the hide mode, how can I close the Adobe program.  I am a very novice programmer.  Below is the code for the section of the Adobe Acrobat program.  I tried a couple of things but it did not work.  Thanks in advance for your help.

Public Sub createProcess(sLocation As String)
    On Error GoTo ErrorHandler
   
  Dim pid&
  Dim FoundFlag As Boolean
  Dim hwndJob As Long

  Dim gApp As Acrobat.CAcroApp
  Dim gAVDoc As Acrobat.CAcroAVDoc
  Dim gPDDoc As Object
 
  Dim objPDF As Object
  Dim iPages As Integer
  Dim lNumPages As Long

'  sLocation = "\" & sLocation
 
  iPages = 0
  lNumPages = 0
 
  Set gApp = CreateObject("AcroExch.App")
  Set gAVDoc = CreateObject("AcroExch.AVDoc")
   
    If gAVDoc.Open("\" & sLocation, "") Then
       'Start Acrobat in hidden mode
       gApp.Hide
       
       Set gPDDoc = gAVDoc.GetPDDoc
       ' Determine number of pages, subtract 1, because the index starts at 0
       iPages = gPDDoc.GetNumPages - 1
             
       If gAVDoc.PrintPagesSilent(0, iPages, 0, True, True) Then
            Set gAVDoc = Nothing
            Set gApp = Nothing
       Else
            MsgBox "Error Printing"
         '   gAVDoc.Close
            Set gAVDoc = Nothing
            Set gApp = Nothing
       End If
    Else
        'msgbox "write to error log..."
        gAVDoc.Close
    End If

JSLorraine
0
Comment
Question by:JSLorraine
[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
11 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9742668
Just a guess:
 Dim gApp As Acrobat.CAcroApp

hasn't gApp a close or quit method?
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9742695
Try push F2 key when in IDE and search for the library, sure you would get something usefull
0
 
LVL 1

Expert Comment

by:atp_expert
ID: 9747463
I think u need to follow the same procedure what we follow when using MS word from Visual Basic. When a MS word application is opened and processing is over, we will release it from memory (setting the object to nothing), and close the application. Try the same for adobe application
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!

 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9748720
You could use a different approach and don't use automation at all:

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

'and for each file:

shellexecute me.hwnd,"print,"path_and_filename_goes_here",vbnullstring,vbnullstring,vbhide
0
 

Author Comment

by:JSLorraine
ID: 9750818
Concerning the use of the ShellExecute, we use to do the process in that manner, but we are now accessing the systems .ini and pulling in the printer ids.  The application prints at a number of different sites.  When the document is retrieved, it prints at the specified site as stated in the file information.  I can't remember the details, but with the execution of the application, we were running into memory problems.  

In the program as shown above, I do have the application equalling 'nothing', but the application did not shut down.  I also tried 'exit', but to no avail, the application does not shut down.  

Any ideas would be greatly appreciated.
Thanks,
JSLorraine
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9750902
"....
I also tried 'exit', but to no avail, the application does not shut down.  
...."
Did you use F2 key to see the methods and properties of  Acrobat.CAcroApp class?
0
 

Author Comment

by:JSLorraine
ID: 9751023
Yes,  this is what was displayed:  Member of Acrobat.CAcroApp
    Exits the Acrobat viewer. Applications should call App.Exit() before exiting.  
I have tried this, but when I run the application in debug mode, and looking at the task manager, the Adobe Acrobat application does not close.  When I view the list of applications open, I continually refresh the view, before I have executed the program, during the program, and after I have executed the App.Exit.  

Since I do not know VB very good, where I had the coding in the program of:
 'If gAVDoc.PrintPagesSilent(0, iPages, 0, True, True) Then
            Set gAVDoc = Nothing'
in place of 'Set gAVDoc = Nothing' I used 'gApp.Exit'.  Is there a problem with that?
Thanks much,
JSLorraine
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9751071
It should be

....
.....

 If gAVDoc.PrintPagesSilent(0, iPages, 0, True, True) Then
            Set gAVDoc = Nothing
            Set gApp = Nothing
       Else
            MsgBox "Error Printing"
            gAVDoc.Close
            Set gAVDoc = Nothing
            gApp.exit
            Set gApp = Nothing
       End If
...
....
0
 
LVL 3

Expert Comment

by:TimW1
ID: 9761111
if you can get a handle to the acrobat program you can use the SendMessage API and issue a wm_close command.  That will tell acrobat to close.  If you can't get a handle to the window you need to use the EnumWindows api (which is a little more complicated) to get the handle, then issue the close command.

I haven't used the acrobat dll or ocx but does it have an hWnd or an application.hwnd property.  If it does you might be able to use that.

Private Const WM_CLOSE = &H10
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Dim lRet as long
Dim lhWnd as long
lhWnd = ' Get the windows handle
lRet = SendMessage(lhWnd, wm_close, 0, 0)  'Can't remember much about wParam and lParam, may need to look into those.

If you need help with getting the handle to the window let me know, I have it somewhere but its a call back and more complicated.

Tim
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 500 total points
ID: 10548258
Moderator, my recommended disposition is:

    Save as PAQ -- No Refund.

Dan Rollins -- EE database cleanup volunteer
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

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…
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…
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…

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