In PDF language, we often use the terms outline tree or outlines as synonyms for bookmarks. In topic 2, you created bookmarks automatically by using topic and Section objects. The result was nice, but you can do better if you create the outline using PdfOutline objects. The PdfOutline class offers much more functionality, and you can use it to create bookmarks for existing documents. Take a look at figure 7. The bookmarks consist of movie titles printed in bold; one of the movie titles is shown using Korean characters.

Author:Zulkikora Modal
Language:English (Spanish)
Published (Last):3 August 2005
PDF File Size:3.40 Mb
ePub File Size:9.30 Mb
Price:Free* [*Free Regsitration Required]

Following earlier articles in my iTextSharp series, this particular contribution will introduce the basics of linking and bookmarking PDF documents created via iTextSharp. You may want to review earlier articles in this series, if you haven't already done so. For that reason, I suggest applying underlining and a blue colour to the font, as this should help users identify an Anchor as providing some functionality:. MapPath "PDFs" ;. Create ;. GetFont "Arial" , 12, Font.

The code sample above creates an external link, which when clicked will open a browser at this site. The first paragraph contains the text "Click to go to Target", and its reference is set to " target", just as with the HTML version. The second paragraph adds some empty lines and the final paragraph contains a new Anchor, with a Name attribute set to match the Reference value in the Anchor in the first paragraph. The result is that if you click on the "Click to go to the Target" text, the PDF will immediately reposition itself so that "This is the Target" will be at the top of whatever PDF viewer you are using.

Add new Chunk "Click " ;. Add new Chunk "here" , link. Add new Chunk " to find local goto" ;. Add new Chunk "Local Goto Destination". The first chunk is added using the font that's set up to convey to users that the text should act as a hyperlink.

The Chunk. SetLocalGoto method accepts a string, which acts a a label for the target. A number of empty lines are added followed by another chunk. This one has its SetLocalDestination method invoked, again with a string defining the location of the target. It's matches the one set in the SetLocalGoto method earlier. When rendered to the PDF, the word "here" is underlined and in blue, and clicking on it brings "Local Goto Destination" to the top of the screen.

Often when you open a PDF file, your PDF Viewer application displays a tree-view of the structure of the document, with each branch or leaf acting as a link to the corresponding chapter or section. The top-level object is a Chapter, which will always begin on a new page. Sections cannot be added alone, but must be added to Chapter objects, or parent Section objects:.

AddSection 20f, "Section 1. AddSection 20f, "Subsection 1. AddSection 20f, "Sub Subsection 1. AddSection "Section 2. AddSection "Subsection 2. The image above helps to explain the preceding code. Initially, a Chapter object is created with a Paragraph passed in as the first argument. The second argument is the number of the Chapter - in this case 1. Nest, a Section object is added to the Chapter, with 3 arguments: a float specifying the left indentation in points; the title of the Section to appear on the page and in the Bookmarks; and the indentation depth for the entry in the Bookmarks tree.

In this case, Section 1. Subsection1 is added to Section 2 and has been told to appear as a third-level entry in the tree. The rest of the code that adds Chapters and Sections should be straightforward. The final lines of code show that the actual entry in the Bookmarks can be changed from the title on the page by setting the BookMarkTitle property to another string value.

Then the outline view for the tree is set as open for Chapter 1, but closed for Chapter 2. Finally, both Chapters are added to the document. Chapters and Sections are pretty memory hungry, so they should be used judiciously. If you need to create a document such as a manual on a regular basis, this might be a task best scheduled for quieter times on your web server.

C ASP. NET 3. Write dex. Write ioex. Add click ; doc. Add target ; doc. Add p3 ;. Add new Chunk "Click " ; p4. Add new Chunk " to find local goto" ; p4. Add p4 ; doc. Add p5 ;. Add chapter1 ; doc. Add chapter2 ;. This site uses cookies to analyse traffic, remember your preferences, and optimise your experience. Learn more Close.


Adding bookmarks (iText 5)

By using our site, you acknowledge that you have read and understand our Cookie Policy , Privacy Policy , and our Terms of Service. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. My requirement is same as described in this question: Bookmark to specific page using iTextSharp 4. Bookmarks are discussed in Chapter 7 where you'll find the BookmarkedTimeTable example. As you're working with iTextSharp C , not iText Java , you'll want to look up the corresponding example in the list of examples ported to C , more specifically BookmarkedTimeTable. Please start with the example from my book, and then change that example gradually until you break that code. When a PDF is digitally signed, there is a limited number of operations that may or may not be allowed.


iTextSharp - Links and Bookmarks

Learn about trends and get answers to your biggest Citrix questions! Listen Now. Select all Open in new window. IT issues often require a personalized solution. Get Free Limited Access. Why EE?


Add Page bookmark to an existing PDF using iTextSharp in C#

Last post May 20, AM by Sreekanth For adding Link in pdf file. The top-level object is a Chapter, which will always begin on a new page. Sections cannot be added alone, but must be added to Chapter objects, or parent Section objects:. It is for merge pdf files and add bookmarks to it. I guess, you have not added the pages in your pdf because of which bookmark was not working.

Related Articles