Chapter 7. Making documents interactive

 

This chapter covers

  • Creating actions and destinations
  • Working with outlines and bookmarks
  • Adding annotations and JavaScript

In the summary of the previous chapter, table 6.1 outlined the most important iText classes for manipulating documents. You’ve used these classes to manipulate the content of existing documents to copy pages, add extra content, fill out forms, and so forth. In this chapter, you’ll use PdfStamper and PdfCopy to add interactive features to an existing document.

We’ll start by adding actions that will help the end user navigate through the document, similar to what you did with internal and external links in section 2.3.1. Next we’ll look at bookmarks, but instead of using Chapters and Sections, as you did in section 2.3.2, we’ll look at how to create a custom outline tree. Finally, we’ll add annotations. For example, you’ll learn how to put a sticky note on an existing page, and how to show an advertisement when a PDF document is opened.

7.1. Introducing actions

If you’re reading this book from beginning to end, actions shouldn’t be new to you. You created documents containing actions in chapter 2, but we didn’t call them actions; instead we talked about remote and local goto links. In this section, you’ll add goto actions using the PdfAction class, and you’ll also learn how to introduce new actions, such as actions that trigger JavaScript functions embedded in the document.

7.2. Adding bookmarks

7.3. Creating annotations

7.4. JavaScript programming in PDF

7.5. Summary