When we read books on paper, we look over the catalog for the page numbers. Then, turn to the corresponding page manually. For e-books, the navigation function helps us to do that. Just by clicking, the content you want to read will display in front of your eyes.
The function of navigation can be achieved by links and bookmarks. ComPDFKit PDF SDK provides the functionality of navigation. Let’s see how to apply the navigation to the e-book industry in code methods.
Even now, we may find some kinds of e-books without navigation. After you know the page number from the catalog, you can’t jump to specific pages immediately. That’s maddening. To figure these problems out, navigation is a pretty convenient and important function and is widely used in e-books.
Some writers may want to recommend another book to their readers. They can just add a link to the content. There are more situations for you to apply the navigation function such as catalog in front of the book contents, outline beside the book contents, links and bookmarks in the books, etc.
The links are used in the books for internal and external linking. For internal links, we can add a link to a page, a point, or a specified rectangle on a page. This is usually used in reference, study guide e-books for connecting to related information. Here we will present how to add, delete, and exchange the links by code.
The picture above is a part of an e-book. I want to add a link to the words “ComPDFKit PDF SDK”. So that the page will jump to page 4 after clicking the words. The code methods are shown as follows.
NSURL *url = [NSURL fileURLWithPath:@""]; CPDFDocument *document = [[CPDFDocument alloc] initWithURL:url]; CPDFSelection *selection = pdfView.currentSelection; CPDFDestination *destination = [[CPDFDestination alloc] initWithDocument:document pageIndex:3]; CPDFLinkAnnotation *link = [[CPDFLinkAnnotation alloc] initWithDocument:document]; link.bounds = selection.bounds; link.destination = destination; [selection.page addAnnotation:link];
Now, the code below is for exchanging the links to let the page jump to page 10.
CPDFDestination *destination = [[CPDFDestination alloc] initWithDocument:document pageIndex:9]; link.destination = destination;
Bookmarks are a tool for readers to mark special places like the interesting parts of stories or the current reading page. When you want to see the section you marked, just click the bookmark.
Take the following picture as an example. We also show you how to add, delete, or exchange a bookmark in the section of “Requirements”.
NSURL *url = [NSURL fileURLWithPath:@""]; CPDFDocument *document = [[CPDFDocument alloc] initWithURL:url]; CPDFSelection *selection = pdfView.currentSelection; NSInteger pageIndex = [document indexForPage:selection.page]; [document addBookmark:@"Requirements" forPageIndex:pageIndex];
From now on, do you find the difference between links and bookmarks? As we mentioned above. They all can connect to another specific place. And the ability to turn to another page or content is achieved by links. The only difference is links are in the content of PDF files. But the bookmarks are detached from the text.
That’s to say. Wherever you read, you can jump to another part by bookmarks. To make a bookmark detached from the text, will be needed. After knowing that, do you know what the outline is?