concept Paragraph in category itext

appears as: Paragraph, Paragraph, The Paragraph
iText in Action, Second Edition

This is an excerpt from Manning's book iText in Action, Second Edition.

Document is the object to which you’ll add content in the form of Chunk, Phrase, Paragraph, and other high-level objects. These objects are often referred to as iText’s basic building blocks, and they’ll be discussed in chapter 2. For now, we’ll only work with Paragraph objects.

We’ll discuss a first series of objects in section 2.2: Chunk, Phrase, Paragraph, and List. In section 2.3, we’ll cover a second series: Anchor, Chapter, Section, and Image. But before starting to build documents using these building blocks, let’s have a look at the database you’ll publish to different PDF files in the upcoming examples.

2.2.3. Paragraph object: a Phrase with extra properties and a newline

Although the analogy isn’t entirely correct, I often compare the difference between a Phrase and a Paragraph in iText with the difference between <span> and <div> in HTML. If you had used a Paragraph instead of a Phrase in the previous examples, it wouldn’t have been necessary to add a newline.

Listing 2.6. MovieTitles.java
List<Movie> movies = PojoFactory.getMovies(connection); for (Movie movie : movies) { document.add(new Paragraph(movie.getTitle())); }

The Paragraph class is derived from the Phrase class. You can create instances of Paragraph exactly the same way as you’ve been creating Phrase objects, but there’s more: you can also define the alignment of the text, different indentations, and the spacing before and after the paragraph.

Figure 5.5. Page events for Chunks and Paragraphs