I was wondering if there was a way to transfer bookmarks from one pdf file to another pfd file. I am doing this so the user of the collection has a easy way of navigation. Thanks!
Hi,
Its certainly possible to do it via replacing pages using Adobe Exchange; i.e replace everything but the title page. Its a little messy, and just gets worse when the size of items change so the bookmark destination changes.
here is the code to copy a bookmark into an other PDF file :
(works only for links to pages in the PDF)
I hope it will be helpfull to you : )
Option Explicit
Const d = "c:\temp" -- change it to match an existing directory with pdf files and create a sub directory "new" where you place the file which need the copy of the bookmark (in this sample the two file need to have the same name, you can change it if you want)
Const s = "test.pdf" -- the pdf file with the bookmark to copy
Public avance As Integer
Dim gs_b(1000, 2) As String
Dim gs_bn(1000, 2) As String
Public Sub main()
Dim app As Acrobat.CAcroApp
Dim path As String
Dim pathb As String
Dim PDDoc As Acrobat.CAcroPDDoc
Dim newdoc As Acrobat.CAcroPDDoc
Dim pad As Acrobat.CAcroPDPage
Dim avd As Acrobat.CAcroAVDoc
Dim avp As Acrobat.CAcroAVPageView
Dim jso As Object
Dim Bookmark As Variant
Dim bok As Variant
Dim bk As Object
Dim BookMarkRoot As Object
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim taille As Integer
Dim q As Integer
Dim a As Integer
Dim te As Boolean
Screen.MousePointer = 11
Set app = CreateObject("AcroExch.App"
Set PDDoc = CreateObject("AcroExch.PDDoc"
Set avd = CreateObject("AcroExch.AVDoc"
path = d & "\" & s
If avd.Open(path, "temp" Then
Set avp = avd.GetAVPageView
Set PDDoc = avp.GetDoc
Set jso = PDDoc.GetJSObject
Set BookMarkRoot = jso.BookMarkRoot
jso.Layout = "SinglePage" 'on ne voit qu'une page à l'écran
i = 0
q = 0
bok = jso.BookMarkRoot.Children
avance = 1
taille = UBound(bok)
For i = 0 To taille
gs_bn(q, 0) = bok(i).Name
bok(i).Execute
Set pad = avp.GetPage
gs_bn(q, 1) = pad.GetNumber
gs_bn(q, 2) = avance
q = q + 1
q = dochildbis(i, bok, q, avp)
Next
avance = 0
PDDoc.Close
avd.Close (0)
Set newdoc = CreateObject("AcroExch.PDDoc"
pathb = d & "\new\" & s
Call avd.Open(pathb, "tmp"
avd.BringToFront
Set avp = avd.GetAVPageView
Set newdoc = avp.GetDoc
On Error GoTo erre
Set jso = newdoc.GetJSObject
Set bk = jso.BookMarkRoot
a = 0
avance = 0
te = False
For k = 0 To q - 120
avp.GoTo (CInt(gs_bn(k, 1)))
bk.createChild gs_bn(k, 0), "this.pageNum = " & CInt(gs_bn(k, 1)), avance
avance = avance + 1
If k < q - 1 Then
If (CInt(gs_bn(k + 1, 2)) > CInt(gs_bn(k, 2))) Then
Bookmark = bk.Children
a = UBound(Bookmark)
Set bk = Bookmark(a)
avance = 0
End If
If (CInt(gs_bn(k + 1, 2)) < CInt(gs_bn(k, 2))) Then
i = CInt(gs_bn(k + 1, 2))
j = CInt(gs_bn(k, 2))
Do While i < j
Set bk = bk.Parent
avance = UBound(bk.Children) + 1
i = i + 1
Loop
End If
End If
Next
newdoc.SetPageMode (1)
Call newdoc.Save(1, d & "\new\" & s)
newdoc.Close
avd.Close (0)
End If
app.Exit
Screen.MousePointer = 0
Exit Sub
erre:
PDDoc.Close
avd.Close (0)
app.Exit
Screen.MousePointer = 0
MsgBox "Erreur de creation des bookmarks!!!", , "Erreur"
Exit Sub
End Sub
Public Function dochildbis(ind As Integer, bk As Variant, pos As Integer, a As CAcroAVPageView) As Integer
Dim bk2 As Variant
Dim t As Integer
Dim fin As Boolean
Dim i As Integer
Dim tmp As Variant
dochildbis = pos
fin = False
On Error GoTo finarbre
bk2 = bk(ind).Children
If fin = False Then
avance = avance + 1
t = UBound(bk2)
For i = 0 To t
gs_bn(pos, 0) = formatString(bk2(i).Name)
bk2(i).Execute
gs_bn(pos, 1) = a.GetPageNum
gs_bn(pos, 2) = avance
pos = pos + 1
pos = dochildbis(i, bk2, pos, a)
Next
avance = avance - 1
dochildbis = pos
End If
Exit Function
finarbre:
fin = True
Resume Next
End Function
Public Function formatString(s As String) As String
Dim tmp As String
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.