Planet PDF Forum Planet PDF Forum
  New Posts New Posts RSS Feed - VBA Bookmark.Children = Acrobat process still open
  FAQ FAQ  Forum Search   Register Register  Login Login

Hi, welcome to the Foxit Planet PDF Forum. If you have PDF or Adobe Acrobat questions then the right place to ask them is here, in this forum.

VBA Bookmark.Children = Acrobat process still open

 Post Reply Post Reply
Author
JDawson View Drop Down
New Member
New Member
Avatar

Joined: 29 Jan 2015
Location: Pennsylvania
Points: 3
Post Options Post Options   Quote JDawson Quote  Post ReplyReply Direct Link To This Post Topic: VBA Bookmark.Children = Acrobat process still open
    Posted: 30 Jan 2015 at 3:32pm
Hi.  When I use the jso object and I access the children of a bookmark node within Excel VBA the Acrobat.exe process is left running.  I tried setting all the objects I could think of to nothing and still the process is left runningShocked.
 
If I close the workbook and Excel and restart Excel and the routine, additional process do not accumulate (thank goodness for that).
 
If anyone can help that would be much appreciated.  I don't like to leave unecessary processes running, especially if I am sharing the app with my colleagues.
 
Here is the code that I have been using to hack at this.
 
<CODE>
Option Explicit
' Requires a reference to:
'   Visual Basic For Applications
'   OLE Automation
'   Adobe Acrobat 10.0 Type Library (perhaps 8.0 might work too)
'   Microsft Scripting Runtime 'For file system scripting (e.g., CreateObject("Scripting.FileSystemObject"))

Sub ListAllBookmarks()
    Dim gApp As AcroApp
    Dim gPDDoc As Acrobat.AcroPDDoc
    Dim gAvDoc As Acrobat.AcroAVDoc
    Dim jso As Object
    Dim FS As FileSystemObject 'For early binding and use of Intellisense
    Dim PDFinfile As String
    Dim BmRoot As Object
    Dim BmChildren As Variant
    Dim BmName As String
    Dim iBmCount As Integer
    Dim I As Integer
    Dim Msg As String
   
    PDFinfile = "J:\Excel\PDF_Javascript_hacks\HasBookmarks_01.pdf"
   
    Set FS = New FileSystemObject
    'Instead you may use; Set FS = CreateObject("Scripting.FileSystemObject")
   
    If Not FS.FileExists(PDFinfile) Then
        MsgBox "Can't find PDF file." & vbCrLf & vbCrLf & PDFinfile, vbOKOnly, "NO PDF FILE FOUND."
        Set FS = Nothing
        Exit Sub
    End If
    Set FS = Nothing
   
    'Either method (CreateObject or New) of starting the app
    'still leaves Acrobat running when done.
    'Also, it does not matter if the app is started or not.
    'Set gApp = CreateObject("AcroExch.App")
    Set gApp = New AcroApp
   
    Set gAvDoc = CreateObject("AcroExch.AVDoc")
   
    ' open the PDF
    If gAvDoc.Open(PDFinfile, "") Then
        'MsgBox "PDF file opened OK"
        Set gPDDoc = gAvDoc.GetPDDoc()
        If gPDDoc Is Nothing Then
            MsgBox "Could not get the PDDoc object"
            Set gAvDoc = Nothing
            If Not gApp Is Nothing Then Set gApp = Nothing
            Exit Sub
        End If
        Set jso = gPDDoc.GetJSObject
        If jso Is Nothing Then
            MsgBox "Could not get the JSO object"
            Set jso = Nothing
            Set gAvDoc = Nothing
            If Not gApp Is Nothing Then Set gApp = Nothing
            Exit Sub
        End If
    Else
        MsgBox "Could not open PDF """ & PDFinfile & """"
        If Not gApp Is Nothing Then Set gApp = Nothing
        Set gAvDoc = Nothing
        If Not gApp Is Nothing Then Set gApp = Nothing
        Exit Sub
    End If
   
    Set BmRoot = jso.bookmarkRoot
    BmName = BmRoot.Name ' Returns "Root"
    MsgBox "Bookmark root name = " & BmName
   
    'The next line of executable code leaves a process (Acrobat.exe *32, using ~32Mb) still running.
    'Closing this workbook and Excel and reopening and running this again
    'does not create additional processes.
    BmChildren = BmRoot.Children 'Returns an array but leaves Acrobat.exe still running when done
    iBmCount = UBound(BmChildren)
    MsgBox "There are " & iBmCount + 1 & " top level bookmarks."
    For I = 0 To UBound(BmChildren)
        BmName = BmChildren(I).Name
        Msg = Msg & vbCrLf & "Level 1 bookmark = " & BmName
        Set BmChildren(I) = Nothing 'Still leaves Acrobat running when done
    Next I
   
    MsgBox Msg
   
    Set BmChildren = Nothing
    Set BmRoot = Nothing
    Set jso = Nothing
    gPDDoc.Close
    gAvDoc.Close (1) 'Close without saving the original PDF
    Set gPDDoc = Nothing
    Set gAvDoc = Nothing
   
    'Closing the app (if started) still leaves Acrobat running when done.
    If Not gApp Is Nothing Then
        gApp.Exit
        Set gApp = Nothing
    End If
End Sub
</CODE>
 
Ja, jag pratar för mig själv. Ibland behöver jag expertråd. Jim
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.10
Copyright ©2001-2017 Web Wiz Ltd.

This page was generated in 0.047 seconds.