Do you own a Debenu Quick PDF Library version 7, 8, 9, 10, 11, 12, 13 or iSEDQuickPDF license? Upgrade to Debenu Quick PDF Library 14 today!

Debenu Quick PDF Library - PDF SDK Community Forum Homepage
Forum Home Forum Home > For Users of the Library > Sample Code
  New Posts New Posts RSS Feed - VB 6 Ading a bookmark treview to your pro
  FAQ FAQ  Forum Search   Register Register  Login Login

VB 6 Ading a bookmark treview to your pro

 Post Reply Post Reply
Author
Message
DELBEKE View Drop Down
Debenu Quick PDF Library Expert
Debenu Quick PDF Library Expert
Avatar

Joined: 31 Oct 05
Location: France
Status: Offline
Points: 151
Post Options Post Options   Thanks (0) Thanks(0)   Quote DELBEKE Quote  Post ReplyReply Direct Link To This Post Topic: VB 6 Ading a bookmark treview to your pro
    Posted: 13 Jul 06 at 4:21AM

 

Option Explicit
'This is a sample to build a treeview
'create a new project
'add a textbox (named Text1)
'add a command buton (named Command1)
'add a treview (named Treeview1)

' the tree is not fully created , childs nodes are added when the user expand the node
' to do so a dummy child is created first
' and destroyed when the parent node is expanded
' then childs are added.
'
' the tag property for each node is used to store the pointed page and the position inside the page

Dim Doc As iSED.QuickPDF

Private Sub Command1_Click()
  Dim strTemp As String
  'control if text1 is filled
  If Trim(Text1) = "" Then
    MsgBox "Fill a valid Pdf File Name in the textbox"
    Exit Sub
  End If
  'control if the file exist nd can be accessed
  On Error Resume Next
  strTemp = Dir(Text1)
  On Error GoTo 0
  If strTemp = "" Then
    MsgBox "Ca'nt read the file"
    Exit Sub
  End If
  'load the pdf
  lRet = Doc.LoadFromFile(Text1)
  If lRet = 0 Then
    MsgBox "The file ca'nt be read"
    Exit Sub
  End If
  'unencryt
  If Doc.Encrypted Then
    Doc.Unencrypt
  End If
  GetOutLines
End Sub

Private Sub Form_Load()
  Set Doc = New iSED.QuickPDF
  Dim lRet As Long
  TreeView1.Style = tvwTreelinesPlusMinusText
  TreeView1.LineStyle = tvwRootLines
  TreeView1.Indentation = 5
  lRet = Doc.UnlockKey("Your Key")
  Doc.SetMeasurementUnits vbPixels
  Doc.SetOrigin 1
End Sub

Private Sub GetOutLines()
  'Get Root Outlines
  Dim lRet As Long
  Dim OutId As Long
  Dim OutText As String
  Dim OutPage As Long
  Dim OutDest As Long
  Dim OutDestPosX As Long
  Dim Nod As Node
  Dim DummyChildNod As Node
  TreeView1.Nodes.Clear
  If Doc.OutlineCount = 0 Then
    'no outlines
    'first create a  root node
    Set Nod = TreeView1.Nodes.Add(, , "K0", "BookMarks")
    Nod.Tag = "1|0"
    'create a node for each page
    For lRet = 1 To Doc.PageCount
      Set DummyChildNod = TreeView1.Nodes.Add(Nod, tvwChild, , "Page " & CStr(lRet))
      DummyChildNod.Tag = CStr(lRet) & "|0"
    Next
    Exit Sub
  End If
 
  OutId = Doc.GetFirstOutline
  If OutId = 0 Then
    'security
    Exit Sub
  End If
  'create then root node
  OutText = Doc.OutlineTitle(OutId)
  Set Nod = TreeView1.Nodes.Add(, , "K" & CStr(OutId), OutText)
  Nod.Tag = GetOutDest(OutId)
  If Doc.GetFirstChildOutline(OutId) <> 0 Then
    'if child exist then create a Dummy node
    Set DummyChildNod = TreeView1.Nodes.Add(Nod, tvwChild, , "Dummy")
    DummyChildNod.Tag = "*"
  End If
  'get the others entry a the root level
  Do While OutId <> 0
    OutId = Doc.GetNextOutline(OutId)
    If OutId = 0 Then
      Exit Do
    End If
    OutText = Doc.OutlineTitle(OutId)
    Set Nod = TreeView1.Nodes.Add(, , "K" & CStr(OutId), OutText)
    Nod.Tag = GetOutDest(OutId)
    If Doc.GetFirstChildOutline(OutId) <> 0 Then
      'if child exist then create a Dummy node
      Set DummyChildNod = TreeView1.Nodes.Add(Nod, tvwChild, , "Dummy")
      DummyChildNod.Tag = "*"
    End If
  Loop
End Sub
Private Sub GetChildOutLines(NodParent As Node)
  'get then childs for this outline
  Dim lRet As Long
  Dim OutId As Long
  Dim OutText As String
  Dim OutPage As Long
  Dim OutDest As Long
  Dim OutDestPosX As Long
  Dim OutParentId As Long
  Dim Nod As Node
  Dim DummyChildNod As Node
  OutParentId = Val(Mid(NodParent.Key, 2))
  Set DummyChildNod = NodParent.Child
  If DummyChildNod Is Nothing Then
    'no childs
    Exit Sub
  End If
  If DummyChildNod.Tag <> "*" Then
    'no dummy child=> already expanded
    Exit Sub
  End If
  'remove the dummy child and
  'create the childs
  TreeView1.Nodes.Remove DummyChildNod.Index
  OutId = Doc.GetFirstChildOutline(OutParentId)
  If OutId = 0 Then
    Exit Sub
  End If
  'create the first child
  OutText = Doc.OutlineTitle(OutId)
  Set Nod = TreeView1.Nodes.Add(NodParent, tvwChild, "K" & CStr(OutId), OutText)
  Nod.Tag = GetOutDest(OutId)
  If Doc.GetFirstChildOutline(OutId) <> 0 Then
    'if child exist then create a Dummy node
    Set DummyChildNod = TreeView1.Nodes.Add(Nod, tvwChild, , "Dummy")
    DummyChildNod.Tag = "*"
  End If
  'get the others entry at the same level
  Do While OutId <> 0
    OutId = Doc.GetNextOutline(OutId)
    If OutId = 0 Then
      Exit Do
    End If
    'create thers node at the same level
    OutText = Doc.OutlineTitle(OutId)
    Set Nod = TreeView1.Nodes.Add(NodParent, tvwChild, "K" & CStr(OutId), OutText)
    Nod.Tag = GetOutDest(OutId)
    If Doc.GetFirstChildOutline(OutId) <> 0 Then
      'if child exist then create a Dummy node
      Set DummyChildNod = TreeView1.Nodes.Add(Nod, tvwChild, , "Dummy")
      DummyChildNod.Tag = "*"
    End If
  Loop
End Sub

Private Function GetOutDest(OutId As Long) As String
  'get page and pos of the destination
  'the result will be stored in the tag of each node
  Dim OutDest As Long
  Dim OutPage As Long
  Dim OutDestPosX As Long
  OutDest = Doc.GetOutlineDest(OutId)
  OutPage = Doc.GetDestPage(OutDest)
  OutDestPosX = Abs(ScaleX(Doc.GetDestValue(OutDest, 2), vbPoints, vbMillimeters))
  If OutDestPosX < 0 Then
    OutDestPosX = 0
  End If
  GetOutDest = CStr(OutPage) & "|" & OutDestPosX
End Function


Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
  'got a selection on the treeview,
  'retrieve the page and position from the top
  Dim iPosit As Integer
  Dim PosX As Long
  Dim Page As Long
 
  If Val(Node.Tag) = 0 Then
    'security
    Exit Sub
  End If
  iPosit = InStr(Node.Tag, "|")
 
  'retrieve the page ans position inside the page
  '
  Page = Val(Left(Node.Tag, iPosit - 1))
  PosX = Val(Mid(Node.Tag, iPosit + 1))
   
  'modify these line to match your needs
  MsgBox "Page " & CStr(Page) & " / Vertical position " & CStr(PosX)
 
End Sub
Private Sub TreeView1_Expand(ByVal Node As MSComctlLib.Node)
  'expand the treeview
  GetChildOutLines Node
End Sub

 

 

Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.01
Copyright ©2001-2014 Web Wiz Ltd.

Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. AboutContactBlogSupportOnline Store