Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Transferring Bookmarks (PDF to PDF) 1

Status
Not open for further replies.

NateUNI

MIS
Jan 3, 2002
132
US
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.

best of luck,

Steve Hall
 
If the bookmark only content links to current PDF page there is a way to do it with VB code (using java script object).

I can send you the code of the vb application if you want.
 
Thanks for the replies, i did however find a plugin that was able to copy bookmarks; isitoolbox. Thanks for the help!
 
ajji,

I would be interested in the code please :)
 
RMS10,

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 & &quot;\new\&quot; & 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 &quot;Erreur de creation des bookmarks!!!&quot;, , &quot;Erreur&quot;
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

tmp = Replace(s, &quot; &quot;, &quot;_&quot;)
tmp = LCase(tmp)
tmp = Replace(tmp, &quot;é&quot;, &quot;e&quot;)
tmp = Replace(tmp, &quot;è&quot;, &quot;e&quot;)
tmp = Replace(tmp, &quot;ê&quot;, &quot;e&quot;)
tmp = Replace(tmp, &quot;ë&quot;, &quot;e&quot;)
tmp = Replace(tmp, &quot;à&quot;, &quot;a&quot;)
tmp = Replace(tmp, &quot;â&quot;, &quot;a&quot;)
tmp = Replace(tmp, &quot;ä&quot;, &quot;a&quot;)
tmp = Replace(tmp, &quot;ù&quot;, &quot;u&quot;)
tmp = Replace(tmp, &quot;ü&quot;, &quot;u&quot;)
tmp = Replace(tmp, &quot;û&quot;, &quot;u&quot;)
tmp = Replace(tmp, &quot;î&quot;, &quot;i&quot;)
tmp = Replace(tmp, &quot;ï&quot;, &quot;i&quot;)
tmp = Replace(tmp, &quot;ö&quot;, &quot;o&quot;)
tmp = Replace(tmp, &quot;ô&quot;, &quot;o&quot;)
tmp = Replace(tmp, &quot;ÿ&quot;, &quot;y&quot;)
tmp = Replace(tmp, &quot;ç&quot;, &quot;c&quot;)
formatString = tmp

End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top