getAllChildren().get(0).getAllChildren(); StringBuffer stringBuffer = new StringBuffer(); for (PdfOutline bookmark: bookmarks) { showTitle(bookmark, stringBuffer); }. Tags: iText 7building blocksChapter 6tutorialactionsdestinationsBookmarks drawn by the PDF viewer that renders annotations on top of the existing content. Interactivity within PDF documents is enabled though Anchors (links) and Bookmarks. Following earlier articles in my iTextSharp series, this.

Author: Zulugrel Arashidal
Country: Guinea-Bissau
Language: English (Spanish)
Genre: Science
Published (Last): 19 December 2012
Pages: 234
PDF File Size: 16.93 Mb
ePub File Size: 13.46 Mb
ISBN: 144-8-72207-119-2
Downloads: 81051
Price: Free* [*Free Regsitration Required]
Uploader: Tozahn

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. If you click the Instant Info bookmark, an alert window opens showing the year and run length of the movie.

This is different from what you did before with topic and Section objects. The first thing you need is the root of the outline tree. You can get this with the get-RootOutline method O.

[Solved] How to import bookmark from XML to existing pdf? – CodeProject

The zoom factor will be adapted so that the complete horizontal width is visible look for FITH in table 7. But if you want to create a PdfDestination object, you need to know the vertical position.

You can retrieve this coordinate with the getVerticalPosition method. It can also ensure that you get the position of the next line. Q adds aJavaScript action. NOTE You can use a Paragraph for the bookmark title, existng the style of the Paragraph object will not be taken into account. Observe that Unicode characters are accepted.


Here you use a similar object to extract the bookmarks from an existing PDF: You first obtain a List of HashMap objects.

Each HashMap item contains at least one itextshharp the keys listed in table 7. You can export the bookmarks list to an XML file O in listing 7. The resulting XML file looks like this: You can use table 7. The root tag is always named Bookmark. The Title tags are used for its existinf. All other key-value pairs are attributes of the Title tag. Obokmark you click one of these dates, the corresponding page is opened.

You can create this outline tree and add it to an existing document using PdfStamper. You can consult table 7. You can use the setOutlines method to add the bookmarks to the stamper object.

This also works for PdfCopy. Both documents have bookmarks, and you want these bookmarks to be merged as shown in figure 7.

iTextSharp – Links and Bookmarks

In this code sample, we concatenate bookmarks, but in listing 6. Just like in the PdfStamper example, you create an ArrayList for the bookmarks. It will point to the first page of the first document in the concatenated PDF.

You use setOutlines to inject the new list of bookmarks into the new document. One of the parameters in O was null. The next section will give you an overview of the open parameters that can be used to achieve this. The following URL opens the documentation about open actions on page 5 using a magnifying factor that ensures that the complete page fits within the viewer window:.

The parameter has the same meaning as described in table 7.


Chapter 6: Creating actions, destinations, and bookmarks

But what really makes a document interactive is annotations. Creating annotations iText 5. Introducing actions Part 2 iText 5. Adding bookmarks iText 5. Creating bookmarks for a new document Take a look at figure 7. Creating annotations iText 5 Previous post: Color values for red, green, and blue ranging from 0 to 1, defining the color of the title. Defines the style of the title. If true, the bookmark is open, showing its kids. A list with the Map s of the sublevel entries of this bookmark.

A destination on a page; see table 7. A path to the file to open or execute; this entry occurs in combination with GoToR and Launch actions.

Indicates whether the file to be opened must be opened in a new window; this entry occurs in combination with the GoToR action. The URL that will be opened if the end user clicks the bookmark. This entry occurs in combination with an URI action. Jumps to a named destination with name name in the PDF.

Jumps to the page with page number pagenum. This number indicates the actual page, not the label you may have given the page. Sets the zoom and scroll factors. A scale value of gives percent zoom; left and top are set in a coordinate system where the origin is the top left of the visible page, regardless of the document rotation.

Sets the zoom factor based on the page size. Opens the file so that the rectangle specified with the parameters is visible.