GdPicture.NET.14.API
GdPicture14 Namespace / GdPicturePDF Class / GetBookmarkNextID Method
A unique bookmark identifier specifying a required bookmark object.

You can obtain this identifier using these methods: GdPicturePDF.NewBookmark, GdPicturePDF.GetBookmarkRootID, GdPicturePDF.GetBookmarkFirstChildID, GdPicturePDF.GetBookmarkPrevID or GdPicturePDF.GetBookmarkParentID.

Example





GetBookmarkNextID Method (GdPicturePDF)
Returns a unique identifier of the next bookmark item located on the same level as a specified bookmark item in the bookmark's hierarchy of the currently loaded PDF document.
Syntax
'Declaration
 
Public Function GetBookmarkNextID( _
   ByVal BookmarkID As Integer _
) As Integer
 

Parameters

BookmarkID
A unique bookmark identifier specifying a required bookmark object.

You can obtain this identifier using these methods: GdPicturePDF.NewBookmark, GdPicturePDF.GetBookmarkRootID, GdPicturePDF.GetBookmarkFirstChildID, GdPicturePDF.GetBookmarkPrevID or GdPicturePDF.GetBookmarkParentID.

Return Value

A unique bookmark identifier of the next bookmark item located on the same level as the specified bookmark item. The GdPicturePDF.GetStat method can be subsequently used to determine if this method has been successful.
Remarks
This method is only allowed for use with non-encrypted documents.

It is recommend to use the GdPicturePDF.GetStat method to identify the specific reason for the method's failure, if any. For example, if the specified bookmark item has no other next bookmark items available on the same level in the hierarchy, the value of GdPictureStatus.PropertyNotFound is returned.

Example
Both examples shows you how to find out the next (sibling) bookmark item of a specified bookmark.
This example shows you all bookmark items (displaying their titles), which are located on the same level as the root bookmark.
Dim caption As String = "Example: GetBookmarkNextID"
Dim gdpicturePDF As New GdPicturePDF()
Dim status As GdPictureStatus = gdpicturePDF.LoadFromFile("bookmarks.pdf", False)
If status = GdPictureStatus.OK Then
    Dim rootID As Integer = gdpicturePDF.GetBookmarkRootID()
    status = gdpicturePDF.GetStat()
    If status = GdPictureStatus.OK Then
        Dim siblingID As Integer = gdpicturePDF.GetBookmarkNextID(rootID)
        status = gdpicturePDF.GetStat()
        If status = GdPictureStatus.OK Then
            Dim titles1 As String = gdpicturePDF.GetBookmarkTitle(rootID) + vbCrLf
            Dim prevID As Integer = 0
            While (status = GdPictureStatus.OK) AndAlso (siblingID > 0)
                titles1 = titles1 + gdpicturePDF.GetBookmarkTitle(siblingID) + vbCrLf
                prevID = siblingID
                siblingID = gdpicturePDF.GetBookmarkNextID(siblingID)
                status = gdpicturePDF.GetStat()
            End While
            If (status <> GdPictureStatus.OK) AndAlso (status <> GdPictureStatus.PropertyNotFound) Then
                MessageBox.Show("The GetBookmarkNextID() method has failed with the status: " + status.ToString(), caption)
            End If
            
            Dim titles2 As String = ""
            siblingID = prevID
            If status = GdPictureStatus.PropertyNotFound Then
                'No other bookmark is available on the same level as the root bookmark.
                status = GdPictureStatus.OK
            End If
            While (status = GdPictureStatus.OK) AndAlso (siblingID > 0)
                titles2 = titles2 + gdpicturePDF.GetBookmarkTitle(siblingID) + vbCrLf
                siblingID = gdpicturePDF.GetBookmarkPrevID(siblingID)
                status = gdpicturePDF.GetStat()
            End While
            If (status <> GdPictureStatus.OK) AndAlso (status <> GdPictureStatus.PropertyNotFound) Then
                MessageBox.Show("The GetBookmarkPrevID() method has failed with the status: " + status.ToString(), caption)
            End If
            
            If (status = GdPictureStatus.OK) OrElse (status = GdPictureStatus.PropertyNotFound) Then
                MessageBox.Show("From top to bottom:" + vbCrLf + titles1 + vbCrLf + "From bottom to top:" + vbCrLf + titles2 + vbCrLf + "The example has been successfully followed.", caption)
            Else
                MessageBox.Show("The example has NOT been successfully followed. Status: " + status.ToString())
            End If
        Else
            If status = GdPictureStatus.PropertyNotFound Then
                MessageBox.Show("The root bookmark doesn't contain any sibling bookmarks.", caption)
            Else
                MessageBox.Show("The GetBookmarkNextID() method has failed with the status: " + status.ToString(), caption)
            End If
        End If
    Else
        If status = GdPictureStatus.PropertyNotFound Then
            MessageBox.Show("This PDF document doesn't contain any bookmarks.", caption)
        Else
            MessageBox.Show("The GetBookmarkRootID() method has failed with the status: " + status.ToString(), caption)
        End If
    End If
Else
    MessageBox.Show("The file can't be loaded. Status: " + status.ToString(), caption)
End If
gdpicturePDF.Dispose()
This example shows you titles of all bookmark entries in the PDF document organized by the top level (denoted as level 0).
'The main entry point.
Dim caption As String = "Example: GetBookmarkNextID"
Dim gdpicturePDF As New GdPicturePDF()
Dim status As GdPictureStatus = gdpicturePDF.LoadFromFile("bookmarks.pdf", False)
If status = GdPictureStatus.OK Then
    Dim message As String = ""
    Dim rootID As Integer = gdpicturePDF.GetBookmarkRootID()
    status = gdpicturePDF.GetStat()
    If status = GdPictureStatus.OK Then
        'Please see the sub-method below.
        ParseOutlines(gdpicturePDF, rootID, 0, message)
        MessageBox.Show("The example has been followed successfully.", caption)
    Else
        If status = GdPictureStatus.PropertyNotFound Then
            MessageBox.Show("This PDF document doesn't contain any bookmarks.", caption)
        Else
            MessageBox.Show("The GetBookmarkRootID() method has failed with the status: " + status.ToString(), caption)
        End If
End If
Else
    MessageBox.Show("The file can't be loaded. Status: " + status.ToString(), caption)
End If
gdpicturePDF.Dispose()
            
'The sub-method.
Private Sub ParseOutlines(gdpicturePDF As GdPicturePDF, bookmarkID As Integer, level As Integer, ByRef message As String)
    Dim title As String = ""
    Dim status As GdPictureStatus = GdPictureStatus.OK
    While True
        title = gdpicturePDF.GetBookmarkTitle(bookmarkID)
        status = gdpicturePDF.GetStat()
        If status = GdPictureStatus.OK Then
            message = message + "Title: """ + title + """  Level: " + level.ToString() + vbCrLf
        Else
            message = message + "Title: this error occurs - " + status.ToString() + "    Level: " + level.ToString() + vbCrLf
        End If
            
        'Checking children.
        Dim childCount As Integer = gdpicturePDF.GetBookmarkChildCount(bookmarkID)
        status = gdpicturePDF.GetStat()
        If status <> GdPictureStatus.OK Then
            message = message + "This error occurs in GetBookmarkChildCount(): status = " + status.ToString() + vbCrLf
        End If
        If childCount > 0 Then
            Dim childID As Integer = gdpicturePDF.GetBookmarkFirstChildID(bookmarkID)
            status = gdpicturePDF.GetStat()
            If status <> GdPictureStatus.OK Then
                message = message + "This error occurs in GetBookmarkFirstChildID(): status = " + status.ToString() + vbCrLf
            Else
                ParseOutlines(gdpicturePDF, childID, level + 1, message)
            End If
        End If
        'Checking for subsequent bookmarks if the current bookmark has no children.
        bookmarkID = gdpicturePDF.GetBookmarkNextID(bookmarkID)
        status = gdpicturePDF.GetStat()
        If (status <> GdPictureStatus.OK) AndAlso (status <> GdPictureStatus.PropertyNotFound) Then
            message = message + "This error occurs in GetBookmarkNextID(): status = " + status.ToString() + vbCrLf
        End If
            
        If level = 0 Then
            MessageBox.Show(message, "Example: GetBookmarkNextID")
            message = ""
        End If
            
        If bookmarkID = 0 Then
            Exit While
        End If
    End While
    Return
End Sub
See Also