PDF Xpress for .NET - User Guide > How To > Modify PDF Document Content > Create & Delete Bookmarks |
Bookmarks can be added to or removed from a PDF document using the Bookmark methods. PDF bookmarks are constructed as a linked list, with one root node. The following is an example of a bookmark list structure:
In the above example, Chapter One is a child of Root, Chapter Two is a sibling of Chapter One, and Part I is a child of Chapter One.
Each bookmark node in the list is represented by a BookmarkContext object.
The root BookmarkContext of the PDF document's bookmark list can be retrieved by calling GetBookmarkRoot.
A child bookmark can be added to any node in the bookmark list by calling AddBookmarkChild. After one child has been specified, additional siblings are added by calling AddBookmarkSibling.
C# Example |
Copy Code
|
---|---|
// This code demonstrates adding a child bookmark to a node in the bookmark list Accusoft.PdfXpressSdk.PdfXpress pdfXpress1 = null; Accusoft.PdfXpressSdk.Document document = null; BookmarkContext parent = null; try { pdfXpress1 = new PdfXpress(); pdfXpress1.Initialize(); document = new Document(pdfXpress1, "C:\\test.pdf"); parent = document.GetBookmarkRoot(); parent = document.GetBookmarkChild(parent); BookmarkContext child = document.CreateBookmark(); child.Title = "bookmark1"; child.ActionPageNumber = 0; parent = document.GetBookmarkRoot(); } catch (System.Exception) { } finally { if (null != parent) { parent.Dispose(); } if (null != document) { document.Dispose(); } if (null != pdfXpress1) { pdfXpress1.Dispose(); } } |
C# Example |
Copy Code
|
---|---|
// This code demonstrates adding a sibling bookmark to a node in the bookmark list Accusoft.PdfXpressSdk.PdfXpress pdfXpress1 = null; Accusoft.PdfXpressSdk.Document document = null; BookmarkContext parent = null; try { pdfXpress1 = new PdfXpress(); pdfXpress1.Initialize(); document = new Document(pdfXpress1, "C:\\test.pdf"); parent = document.GetBookmarkRoot(); parent = document.GetBookmarkChild(parent); BookmarkContext sibling = document.CreateBookmark(); sibling.Title = "bookmark2"; sibling.ActionPageNumber = 0; parent = document.GetBookmarkRoot(); } catch (System.Exception) { } finally { if (null != parent) { parent.Dispose(); } if (null != document) { document.Dispose(); } if (null != pdfXpress1) { pdfXpress1.Dispose(); } } |
To remove a bookmark from a PDF document, call the RemoveBookmark method.
C# Example |
Copy Code
|
---|---|
// This code demonstrates deleting a bookmark from a PDF file Accusoft.PdfXpressSdk.PdfXpress pdfXpress1 = null; Accusoft.PdfXpressSdk.Document document = null; BookmarkContext parent = null; try { pdfXpress1 = new PdfXpress(); pdfXpress1.Initialize(); document = new Document(pdfXpress1, "C:\\test.pdf"); parent = document.GetBookmarkRoot(); parent = document.GetBookmarkChild(parent); parent = document.GetBookmarkChild(parent); document.RemoveBookmark(parent); } catch (System.Exception) { } finally { if (null != parent) { parent.Dispose(); } if (null != document) { document.Dispose(); } if (null != pdfXpress1) { pdfXpress1.Dispose(); } |