i had used the sample code from the thread "How to get pdf file bookmarks using c#".
it works but it can get the first level bookmark only. how can i get the child bookmark ?
thanks
'Read PDF bookmark
Dim bookmarks As IList(Of Dictionary(Of String, Object)) = SimpleBookmark.GetBookmark(reader)
Dim i As Integer = 0
If Not IsNothing(bookmarks) Then
For Each bookmark In bookmarks
pdf_bookmark += bookmarks(i).Values(0).ToString()
If i < bookmarks.Count - 1 Then
pdf_bookmark += ", "
End If
i = i + 1
Next
End If
Check Out this PDF Viewer. It can get PDF both the first level bookmark and children level bookmark. But the code is a little
complex. I just show you the key code below:
Private Sub LoadBookmarks()
If Me.pdfDocumentViewer1.IsDocumentLoaded Then
Dim container As PdfDocumentBookmarkContainer = Me.pdfDocumentViewer1.GetBookmarkContainer()
If container Is Nothing Then
MessageBox.Show("Current PDF document has not bookmarks")
Return
End If
Me.treeViewBookmark.Nodes.Clear()
Dim bookmarks() As PdfDocumentBookmark = container.Childs
For i As Integer = 0 To bookmarks.Length - 1
Dim bookmark As PdfDocumentBookmark = bookmarks(i)
Dim node As New TreeNode()
Dim title As String = bookmark.Title
node.Text = title
node.ForeColor = bookmark.Color
Dim style As FontStyle = CType(bookmark.Style, FontStyle)
Dim font As Font = Me.treeViewBookmark.Font
node.NodeFont = New Font(font, style)
node.Tag = bookmark
Me.treeViewBookmark.Nodes.Add(node)
Me.LoadChidNode(node)
Next i
End If
End Sub
''' Load specified bookmark children bookmark
Private Sub LoadChidNode(ByVal node As TreeNode)
Dim bookmark As PdfDocumentBookmark = TryCast(node.Tag, PdfDocumentBookmark)
Dim childCount As Integer = bookmark.Children.Count
If childCount > 0 Then
For i As Integer = 0 To childCount - 1
Dim childBookmark As PdfDocumentBookmark = bookmark.Children(i)
Dim childNode As New TreeNode()
childNode.Text = childBookmark.Title
childNode.ForeColor = childBookmark.Color
Dim style As FontStyle = CType(bookmark.Style, FontStyle)
Dim font As Font = Me.treeViewBookmark.Font
childNode.NodeFont = New Font(font, style)
childNode.Tag = childBookmark
node.Nodes.Add(childNode)
LoadChidNode(childNode)
Next i
End If
End Sub
''' Go to PDF document bookmark
Private Sub treeViewBookmark_AfterSelect(ByVal sender As Object, ByVal e As TreeViewEventArgs) Handles treeViewBookmark.AfterSelect
Dim node As TreeNode = e.Node
Dim bookmark As PdfDocumentBookmark = CType(node.Tag, PdfDocumentBookmark)
Me.pdfDocumentViewer1.GoToBookmark(bookmark)
End Sub
joeyan
Member
210 Points
90 Posts
How to get PDF child bookmark with VB
Jan 23, 2013 05:46 AM|LINK
i had used the sample code from the thread "How to get pdf file bookmarks using c#".
it works but it can get the first level bookmark only. how can i get the child bookmark ?
thanks
'Read PDF bookmark Dim bookmarks As IList(Of Dictionary(Of String, Object)) = SimpleBookmark.GetBookmark(reader) Dim i As Integer = 0 If Not IsNothing(bookmarks) Then For Each bookmark In bookmarks pdf_bookmark += bookmarks(i).Values(0).ToString() If i < bookmarks.Count - 1 Then pdf_bookmark += ", " End If i = i + 1 Next End IfAlicebaby
Member
36 Points
7 Posts
Re: How to get PDF child bookmark with VB
Jan 25, 2013 05:42 AM|LINK
Check Out this PDF Viewer. It can get PDF both the first level bookmark and children level bookmark. But the code is a little complex. I just show you the key code below:
Private Sub LoadBookmarks() If Me.pdfDocumentViewer1.IsDocumentLoaded Then Dim container As PdfDocumentBookmarkContainer = Me.pdfDocumentViewer1.GetBookmarkContainer() If container Is Nothing Then MessageBox.Show("Current PDF document has not bookmarks") Return End If Me.treeViewBookmark.Nodes.Clear() Dim bookmarks() As PdfDocumentBookmark = container.Childs For i As Integer = 0 To bookmarks.Length - 1 Dim bookmark As PdfDocumentBookmark = bookmarks(i) Dim node As New TreeNode() Dim title As String = bookmark.Title node.Text = title node.ForeColor = bookmark.Color Dim style As FontStyle = CType(bookmark.Style, FontStyle) Dim font As Font = Me.treeViewBookmark.Font node.NodeFont = New Font(font, style) node.Tag = bookmark Me.treeViewBookmark.Nodes.Add(node) Me.LoadChidNode(node) Next i End If End Sub ''' Load specified bookmark children bookmark Private Sub LoadChidNode(ByVal node As TreeNode) Dim bookmark As PdfDocumentBookmark = TryCast(node.Tag, PdfDocumentBookmark) Dim childCount As Integer = bookmark.Children.Count If childCount > 0 Then For i As Integer = 0 To childCount - 1 Dim childBookmark As PdfDocumentBookmark = bookmark.Children(i) Dim childNode As New TreeNode() childNode.Text = childBookmark.Title childNode.ForeColor = childBookmark.Color Dim style As FontStyle = CType(bookmark.Style, FontStyle) Dim font As Font = Me.treeViewBookmark.Font childNode.NodeFont = New Font(font, style) childNode.Tag = childBookmark node.Nodes.Add(childNode) LoadChidNode(childNode) Next i End If End Sub ''' Go to PDF document bookmark Private Sub treeViewBookmark_AfterSelect(ByVal sender As Object, ByVal e As TreeViewEventArgs) Handles treeViewBookmark.AfterSelect Dim node As TreeNode = e.Node Dim bookmark As PdfDocumentBookmark = CType(node.Tag, PdfDocumentBookmark) Me.pdfDocumentViewer1.GoToBookmark(bookmark) End Subjoeyan
Member
210 Points
90 Posts
Re: How to get PDF child bookmark with VB
Jan 29, 2013 07:18 AM|LINK
Thanks a lot.
But PDF viewer is not a free tools. Is there any method to get the child bookmark by free tools such as iTextSharp ?