Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1016
  • Last Modified:

Closing the Adobe Acrobat program in an application

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
JSLorraine
Asked:
JSLorraine
1 Solution
 
Richie_SimonettiCommented:
Just a guess:
 Dim gApp As Acrobat.CAcroApp

hasn't gApp a close or quit method?
0
 
Richie_SimonettiCommented:
Try push F2 key when in IDE and search for the library, sure you would get something usefull
0
 
atp_expertCommented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Richie_SimonettiCommented:
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
 
JSLorraineAuthor Commented:
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
 
Richie_SimonettiCommented:
"....
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
 
JSLorraineAuthor Commented:
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
 
Richie_SimonettiCommented:
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
 
TimW1Commented:
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
 
DanRollinsCommented:
Moderator, my recommended disposition is:

    Save as PAQ -- No Refund.

Dan Rollins -- EE database cleanup volunteer
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now