Print Page | Close Window

VBA Bookmark.Children = Acrobat process still open

Printed From: Foxit's Planet PDF Forum
Category: Lets Talk PDF
Forum Name: PDF Developers
Forum Description: This conference is for PDF developers.
URL: http://forums.planetpdf.com/forum_posts.asp?TID=1429
Printed Date: 26 Jan 2020 at 1:14pm
Software Version: Web Wiz Forums 11.10 - http://www.webwizforums.com


Topic: VBA Bookmark.Children = Acrobat process still open
Posted By: JDawson
Subject: VBA Bookmark.Children = Acrobat process still open
Date 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



Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.10 - http://www.webwizforums.com
Copyright ©2001-2017 Web Wiz Ltd. - https://www.webwiz.net