Chapter 5. Table, cell, and page events

 

This chapter covers

  • Cell and table events
  • Events for Chunks, Paragraphs, Chapters, and Sections
  • Page boundaries
  • Adding headers, footers, and watermarks using page events

In chapters 2 and 4, you added content to a document using a plethora of objects and methods available in iText. When adding a Chunk, you were able to use methods to add lines and a background color. When creating a PdfPTable, you could define borders and backgrounds. But what if all of this isn’t sufficient? What if you don’t want a rectangular background for a Chunk, but a custom shape instead, such as an ellipse? What if you want the borders of a PdfPCell to have rounded corners? This chapter explains how to write custom functionality for Chunk, Paragraph, Chapter, Section, PdfPTable, and PdfPCell objects.

In previous examples involving these objects, you’ve seen that iText takes responsibility for creating a new page whenever the content doesn’t fit the current page. You may want to automatically add artifacts with meta-content to each page—perhaps a running head with a title, a footer with the page number, or a watermark. This can be done using page events.

All of this will be covered in this chapter, but let’s first continue with more table examples, and find out how to create table and cell events.

5.1. Decorating tables using table and cell events

5.2. Events for basic building blocks

5.3. Overview of the page boundaries

5.4. Adding page events to PdfWriter

5.5. Summary