GdPicture.NET.14
GdPicture14 Namespace / GdPicturePDF Class / NewBookmark Method
A unique bookmark identifier specifying the parent's bookmark of the newly created bookmark item. Please use the value of 0 if you want to create a root bookmark (the first top-level bookmark item).

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

The title for the newly created bookmark item.
Example





In This Topic
NewBookmark Method (GdPicturePDF)
In This Topic
Creates and appends a new bookmark item to the exisiting bookmark's hierarchy of the currently loaded PDF document.
Syntax
'Declaration
 
Public Function NewBookmark( _
   ByVal ParentBookmarkID As Integer, _
   ByVal Title As String _
) As Integer
public int NewBookmark( 
   int ParentBookmarkID,
   string Title
)
public function NewBookmark( 
    ParentBookmarkID: Integer;
    Title: String
): Integer; 
public function NewBookmark( 
   ParentBookmarkID : int,
   Title : String
) : int;
public: int NewBookmark( 
   int ParentBookmarkID,
   string* Title
) 
public:
int NewBookmark( 
   int ParentBookmarkID,
   String^ Title
) 

Parameters

ParentBookmarkID
A unique bookmark identifier specifying the parent's bookmark of the newly created bookmark item. Please use the value of 0 if you want to create a root bookmark (the first top-level bookmark item).

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

Title
The title for the newly created bookmark item.

Return Value

The unique bookmark identifier of the newly created bookmark item. The 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 GetStat method to identify the specific reason for the method's failure, if any.

Example
How to create a root bookmark item with some child (descendant) bookmark items.

This example creates a bookmark hierarchy with the root bookmark and 10 child bookmark items, each bookmark points to one page in the PDF document. Also a hierarchy with two child bookmark items is created, both child bookmarks open a website link.

Dim caption As String = "Example: NewBookmark"
Dim gdpicturePDF As New GdPicturePDF()
Dim status As GdPictureStatus = gdpicturePDF.NewPDF()
If status = GdPictureStatus.OK Then
    gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft)
    gdpicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitCentimeter)
    Dim fontResName As String = gdpicturePDF.AddStandardFont(PdfStandardFont.PdfStandardFontHelvetica)
    If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
        Dim failure As Boolean = True
        Dim rootBookmark As Integer = gdpicturePDF.NewBookmark(0, "Pages Navigation")
        status = gdpicturePDF.GetStat()
        If status <> GdPictureStatus.OK Then
            MessageBox.Show("The NewBookmark() method (root bookmark for pages) has failed with the status: " + status.ToString(), caption)
        Else
            Dim i As Integer = 0
            Do
                i += 1
                If (gdpicturePDF.NewPage(21, 29.7F) = GdPictureStatus.OK) AndAlso
                   (gdpicturePDF.SetFillColor(255, 0, 0) = GdPictureStatus.OK) AndAlso
                   (gdpicturePDF.SetTextSize(12) = GdPictureStatus.OK) AndAlso
                   (gdpicturePDF.DrawText(fontResName, 1, 1, "This is the page " + i.ToString()) = GdPictureStatus.OK) Then
                    Dim actionID As Integer = gdpicturePDF.NewActionGoTo(PdfDestinationType.DestinationTypeXYZ, i, 0, 0, 0, 0, 1)
                    If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
                        Dim bookMarkID As Integer = gdpicturePDF.NewBookmark(rootBookmark, "Move to the page " + i.ToString())
                        If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
                            failure = (gdpicturePDF.SetBookmarkAction(bookMarkID, actionID) <> GdPictureStatus.OK)
                        End If
                    End If
                End If
                If failure Then
                    MessageBox.Show("The error occurs when creating a page nr." + i.ToString() + " or an action or a bookmark on this page. Status: " + gdpicturePDF.GetStat().ToString(), caption)
                End If
            Loop While Not failure AndAlso i < 10
        End If
        If Not failure Then
            failure = True
            rootBookmark = gdpicturePDF.NewBookmark(0, "Links Navigation")
            status = gdpicturePDF.GetStat()
            If status <> GdPictureStatus.OK Then
                MessageBox.Show("The NewBookmark() method (root bookmark for links) has failed with the status: " + status.ToString(), caption)
            Else
                Dim bookMarkID1 As Integer = gdpicturePDF.NewBookmark(rootBookmark, "Visit GdPicture website!")
                status = gdpicturePDF.GetStat()
                Dim bookMarkID2 As Integer = 0
                If status = GdPictureStatus.OK Then
                    bookMarkID2 = gdpicturePDF.NewBookmark(rootBookmark, "Read GdPicture.NET documentation online!")
                    status = gdpicturePDF.GetStat()
                End If
                If status = GdPictureStatus.OK Then
                    Dim actionID1 As Integer = gdpicturePDF.NewActionURI("http://www.gdpicture.com", False)
                    status = gdpicturePDF.GetStat()
                    Dim actionID2 As Integer = -1
                    If status = GdPictureStatus.OK Then
                        actionID2 = gdpicturePDF.NewActionURI("http://www.guides.gdpicture.com", False)
                        status = gdpicturePDF.GetStat()
                    End If
                    If status = GdPictureStatus.OK Then
                        failure = ((gdpicturePDF.SetBookmarkAction(bookMarkID1, actionID1) <> GdPictureStatus.OK) OrElse
                                   (gdpicturePDF.SetBookmarkAction(bookMarkID2, actionID2) <> GdPictureStatus.OK))
                        If failure Then
                            MessageBox.Show("This error occurs in creating the link navigation bookmark hierarchy: " + status.ToString(), caption)
                        End If
                    End If
                End If
            End If
        End If
        If Not failure Then
            status = gdpicturePDF.SaveToFile("bookmarks_NewBookmark.pdf")
            If status = GdPictureStatus.OK Then
                MessageBox.Show("The new file has been saved successfully.", caption)
            Else
                MessageBox.Show("The new file can't be saved. Status: " + status.ToString(), caption)
            End If
        End If
    End If
Else
    MessageBox.Show("The new file can't be created. Status: " + status.ToString(), caption)
End If
gdpicturePDF.Dispose()
string caption = "Example: NewBookmark";
GdPicturePDF gdpicturePDF = new GdPicturePDF();
GdPictureStatus status = gdpicturePDF.NewPDF();
if (status == GdPictureStatus.OK)
{
    gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft);
    gdpicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitCentimeter);
    string fontResName = gdpicturePDF.AddStandardFont(PdfStandardFont.PdfStandardFontHelvetica);
    if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
    {
        bool failure = true;
        int rootBookmark = gdpicturePDF.NewBookmark(0, "Pages Navigation");
        status = gdpicturePDF.GetStat();
        if (status != GdPictureStatus.OK)
            MessageBox.Show("The NewBookmark() method (root bookmark for pages) has failed with the status: " + status.ToString(), caption);
        else
        {
            int i = 0;
            do
            {
                i++;
                if ((gdpicturePDF.NewPage(21, 29.7f) == GdPictureStatus.OK) &&
                    (gdpicturePDF.SetFillColor(255, 0, 0) == GdPictureStatus.OK) &&
                    (gdpicturePDF.SetTextSize(12) == GdPictureStatus.OK) &&
                    (gdpicturePDF.DrawText(fontResName, 1, 1, "This is the page " + i.ToString()) == GdPictureStatus.OK))
                {
                    int actionID = gdpicturePDF.NewActionGoTo(PdfDestinationType.DestinationTypeXYZ, i, 0, 0, 0, 0, 1);
                    if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
                    {
                        int bookMarkID = gdpicturePDF.NewBookmark(rootBookmark, "Move to the page " + i.ToString());
                        if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
                        {
                            failure = (gdpicturePDF.SetBookmarkAction(bookMarkID, actionID) != GdPictureStatus.OK);
                        }
                    }
                }
                if (failure)
                    MessageBox.Show("The error occurs when creating a page nr." + i.ToString() + " or an action or a bookmark on this page. Status: " + gdpicturePDF.GetStat().ToString(), caption);
            } while (!failure && i < 10);
        }
        if (!failure)
        {
            failure = true;
            rootBookmark = gdpicturePDF.NewBookmark(0, "Links Navigation");
            status = gdpicturePDF.GetStat();
            if (status != GdPictureStatus.OK)
                MessageBox.Show("The NewBookmark() method (root bookmark for links) has failed with the status: " + status.ToString(), caption);
            else
            {
                int bookMarkID1 = gdpicturePDF.NewBookmark(rootBookmark, "Visit GdPicture website!");
                status = gdpicturePDF.GetStat();
                int bookMarkID2 = 0;
                if (status == GdPictureStatus.OK)
                {
                    bookMarkID2 = gdpicturePDF.NewBookmark(rootBookmark, "Read GdPicture.NET documentation online!");
                    status = gdpicturePDF.GetStat();
                }
                if (status == GdPictureStatus.OK)
                {
                    int actionID1 = gdpicturePDF.NewActionURI("http://www.gdpicture.com", false);
                    status = gdpicturePDF.GetStat();
                    int actionID2 = -1;
                    if (status == GdPictureStatus.OK)
                    {
                        actionID2 = gdpicturePDF.NewActionURI("http://www.guides.gdpicture.com", false);
                        status = gdpicturePDF.GetStat();
                    }
                    if (status == GdPictureStatus.OK)
                    {
                        failure = ((gdpicturePDF.SetBookmarkAction(bookMarkID1, actionID1) != GdPictureStatus.OK) ||
                                  (gdpicturePDF.SetBookmarkAction(bookMarkID2, actionID2) != GdPictureStatus.OK));
                        if (failure)
                            MessageBox.Show("This error occurs in creating the link navigation bookmark hierarchy: " + status.ToString(), caption);
                    }
                }
            }
        }
        if (!failure)
        {
            status = gdpicturePDF.SaveToFile("bookmarks_NewBookmark.pdf");
            if (status == GdPictureStatus.OK)
                MessageBox.Show("The new file has been saved successfully.", caption);
            else
                MessageBox.Show("The new file can't be saved. Status: " + status.ToString(), caption);
        }
    }
}
else
{
    MessageBox.Show("The new file can't be created. Status: " + status.ToString(), caption);
}
gdpicturePDF.Dispose();
See Also