This can be done if and only if the bookmarks you are using for the split go to a page, by using the bookmark "execute" method.
You are aware bookmarks can do far more then go to a page?
Well why don't you show us what you've got and explain what parts you don't understand so that we can help you better understand the method?
I have the following line of Code. However I have no clue how to use the Execute method to split the PDF. Please if anyone can help me with this.
I have removed some of the lines in code for simplicity.
>Private Sub SplitPDF()
> Dim PDFDoc As Object
> Dim JSO As Object
> Dim PDFCompletePath As String
> PDFCompletePath = "C:\Documents and Settings\ragarwal\My Documents\My Docs\PDFTest\Test.pdf"
> Dim BookMarkRoot As Object
> Dim BookMarks As Variant
> Dim LevelCount As Long
> Set PDFDoc = CreateObject("AcroExch.PDDoc")
> If PDFDoc.Open(PDFCompletePath) Then
> Set JSO = PDFDoc.GetJSObject
> BookMarks = JSO.BookMarkRoot.Children
> LevelCount = UBound(BookMarks)
> Dim FirstNode
> FirstNode = BookMarks(0).Children
> Dim i As Integer
> Dim CurrentRootNode
> For i = 0 To LevelCount
> CurrentRootNode = BookMarks(i).Children
> End If
> Exit Sub
There is no method to find out the page for a bookmark directly. (A
bookmark might not even go to a page).
But if your bookmarks are all "normal" (for example, you don't have a
bookmark to open a new file), you can use the Execute method. After
using Execute the current page of the document will tell you,
indirectly, where the bookmark went. You can then record all of this
information and use it later.
Thanks Aandi for your reply.
However, what I am mainly interested is finding a way to split the PDF Files using bookmarks.
All bookmarks in my PDF Files corresponds to a page.
What I understand from your reply is, by using the Execute method, I can go to the page in the Bookmark. But how do I split the PDF.
Does Adobe provides a standard method wherein I can split all the pages in a PDF file using a bookmark.
I am able to do this using ArtsPro PDF Splitter or PDSplit.
>What I understand from your reply is, by using the Execute method, I can go to the page in the Bookmark. But how do I split the PDF.
Some combination of creating a new document, PDDoc.InsertPages, and
>Does Adobe provides a standard method wherein I can split all the pages in a PDF file using a bookmark.
>I am able to do this using ArtsPro PDF Splitter or PDSplit.
That's why they sell it...!
that can split a PDF by top-level bookmarks (or chapters, as I call it). See
I couldn't find much information online about this myself, but hammered away until it worked. You should easily be able to adjust it for your needs.
- Adobe IAC Developer Guide
- Adobe IAC API Reference
- Adobe JS API Reference
- Adobe Acrobat and VBA – An Introduction | Karl Heinz Kremer's Ramblings
- UtterAccess Discussion Forums > Splitting Pdf Files
Private Sub extractBookmark()
Dim AcroApp As AcroApp, AVDoc As AcroAVDoc, PDDoc As AcroPDDoc, PDBookmark As AcroPDBookmark, AVPageView As AcroAVPageView
Dim newPDF As AcroPDDoc, mergePDF As AcroPDDoc
Dim jso As Object, BookMarkRoot As Object
Dim masterPath As String, testName As String, i As Variant, bookmark As Variant
Dim startN As Integer, endN As Integer, nPages As Integer, totalP As Integer
Set AcroApp = CreateObject("AcroExch.App")
Set AVDoc = CreateObject("AcroExch.AVDoc")
Set PDDoc = CreateObject("AcroExch.PDDoc")
Set PDBookmark = CreateObject("AcroExch.PDBookmark")
masterPath = ActiveWorkbook.Path & "\MasterDocument.pdf" 'Path of the PDF containing the bookmarks to be extracted
AVDoc.Open masterPath, vbNull
Set AVPageView = AVDoc.GetAVPageView
Set PDDoc = AVDoc.GetPDDoc
Set jso = PDDoc.GetJSObject
Set BookMarkRoot = jso.BookMarkRoot
bookmark = jso.BookMarkRoot.Children
totalP = PDDoc.GetNumPages
'Loop through the 10 bookmarks in MasterDocument.pdf and get the starting page # of each. This # has to be changed to the # of bookmarks in your pdf. Or write something to count the bookmarks and use that variable. "productName" is a global variable for my specific project... You'll need to revise this for your purpose.
For i = 0 To 9
If bookmark(i).Name = productName Then
PDBookmark.GetByTitle PDDoc, bookmark(i).Name
startN = AVPageView.GetPageNum
If i < 9 Then
PDBookmark.GetByTitle PDDoc, bookmark(i + 1).Name
endN = AVPageView.GetPageNum
nPages = endN - startN
nPages = totalP - startN
'This part will also need to be modified. I am inserting the bookmarks into an already made PDF (global variable for me "fName"). You'll want to create a new pdf.
Set newPDF = CreateObject("AcroExch.PDDoc")
Set mergePDF = CreateObject("AcroExch.PDDoc")
newPDF.Open fName & ".pdf" 'This line needs changing for your purpose. Probably could be.... newPDF.Create
newPDF.InsertPages 0, mergePDF, startN, nPages, 0
newPDF.Save PDSaveFull, fName & ".pdf"