Solved

Closing the Adobe Acrobat program in an application

Posted on 2003-11-13
11
988 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
11 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
Just a guess:
 Dim gApp As Acrobat.CAcroApp

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

Expert Comment

by:Richie_Simonetti
Comment Utility
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
Comment Utility
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
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
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
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
"....
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Moderator, my recommended disposition is:

    Save as PAQ -- No Refund.

Dan Rollins -- EE database cleanup volunteer
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
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…

771 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

8 Experts available now in Live!

Get 1:1 Help Now