Create or remove PDF bookmarks in UWP
When you want to remember a certain page in your document, the easiest way to do this is to add a bookmark.
The current list of bookmarks can be retrieved with GetBookmarksAsync
:
var bookmarks = await pdfView.Document.GetBookmarksAsync();
You can create a bookmark with a name and an Action
and add it to a page like this:
var createdBookmark = await pdfView.Document.CreateBookmarkAsync(new Bookmark("Page 3", new GoTo(2)));
In the code above, you created a bookmark with the name Page 3, which will be displayed in the bookmarks sidebar, and a GoTo
action so that the currently displayed page is changed to the provided page index when the bookmark is clicked on.
The returned Bookmark
object has a property Id
which is used to identify the bookmark when updating or removing it. For example, using the returned bookmark above, you can update it like this:
createdBookmark.Name = "Page 2"; createdBookmark.Action = new GoTo(1); await pdfView.Document.UpdateBookmarkAsync(createdBookmark);
Or you can remove it like this:
await pdfView.Document.DeleteBookmarkAsync(createdBookmark.Id);
You can also create a bookmark from Instant JSON:
{ "id": "this is ignored", "name": "My bookmark", "action": { "type": "goTo", "pageIndex": 2 } }
var bookmarkJson = LoadJsonObjectAsync("bookmark.json"); var createdBookmark = await pdfView.Document.CreateBookmarkAsync(Bookmark.FromJson(bookmarkJson));