Skip to main content
Participating Frequently
April 29, 2019
Answered

I can't seem to get a simple SET JSO statement working consistently in Access Visual Basic.It was working. It looped through PDF bookmarks and split pages based on bookmarks. Bob

  • April 29, 2019
  • 5 replies
  • 1265 views

The following is my code:

Public Function SplitByBookmarks(strPathFile As String)

'THIS COULD BE THE BIG ONE!!!

Dim AVDoc As Acrobat.AcroAVDoc

Dim PDDoc As New Acrobat.AcroPDDoc

Dim NewPDDoc As Acrobat.AcroPDDoc

Dim AVPageView As Acrobat.AcroAVPageView

Dim PDBookmark As AcroPDBookmark

Dim strFile As String, strPath As String, x As Integer, i As Integer

Dim JSO As Object, BookmarkRoot As Object, Bookmarks As Object

Dim PageIndex As Long, PDFFilePath As String, BMArray(50) As String

   

'It gets the bookmarked page!

'Get PDF path and file name  (this will eventually work like the bookmark selection below)

'Set PDF document variables

Set AcroApp = CreateObject("AcroExch.App")

Set AVDoc = CreateObject("AcroExch.AVDoc")

Set PDDoc = CreateObject("AcroExch.PDDoc")

Set NewPDDoc = CreateObject("AcroExch.PDDoc")

Set PDBookmark = CreateObject("AcroExch.PDBookmark")

AVDoc.Open strFile, vbNull

Set AVPageView = AVDoc.GetAVPageView

AcroApp.Show

'***********************************

'SETUP, FIND AND CONVERT BOOKMARKS

Set PDDoc = AVDoc.GetPDDoc

Set JSO = PDDoc.GetJSObject

Set BookmarkRoot = JSO.BookmarkRoot

Bookmarks = JSO.BookmarkRoot.Children

For Each child In Bookmarks

    NewPDDoc.Create

    PDBookmark.GetByTitle PDDoc, child.Name

    PDBookmark.Perform AVDoc

    'PageIndex is zero based

    PageIndex = AVPageView.GetPageNum

    NewPDDoc.InsertPages -1, PDDoc, PageIndex, 1, 0

    PDFFilePath = strPath & child.Name & ".pdf"

    NewPDDoc.Save Acrobat.PDSaveFull, PDFFilePath

    ConvertPDF (PDFFilePath)

    x = x + 1

    BMArray(x) = PDFFilePath

    Set NewPDDoc = Nothing

Next

Set PDDoc = Nothing

For i = 1 To x

    Kill BMArray(i)

Next

Set BookmarkRoot = Nothing

Set JSO = Nothing

PDDoc.Close

End Function

This topic has been closed for replies.
Correct answer Test Screen Name

Please expand on "fails"? Fails in what way? What does it say in the console?

5 replies

Brainiac
April 29, 2019

Actually you STILL didn't tell us what it says in the console. Please do! Because it should clear this up.

Brainiac
April 29, 2019

I wonder if the JSO interface doesn't have enough privileges to run this (and by extension also won't be able to save). This can be overcome, if it's the case, with folder level JavaScript.

Test Screen NameCorrect answer
Brainiac
April 29, 2019

Please expand on "fails"? Fails in what way? What does it say in the console?

Participating Frequently
April 29, 2019

It failed on:

NewPDDoc.Create

so I commented out Set NewPDDoc = nothing

That seemed to work, until I looked at the files.  Instead of one page, it was giving multiple pages incrementally (ie. building every loop, 1,2,3,4, etc.) That's why I inserted Set NewPDDoc = nothing in the first place.  I will try closing the object.

Bernd Alheit
Community Expert
April 29, 2019

Where does you set strFile?

Participating Frequently
April 29, 2019

It looks like I haven't set it.  It should be strPathFile .  Let's see if that works.  Thanks.

Brainiac
April 29, 2019

What do you expect to happen?

What happens?

What does it say in the console?

Have you verified that all the bookmarks contain only characters that are allowed in file names?

Participating Frequently
April 29, 2019

All good suggestions.  I'll take a look and get back with you.