How to maintain a paragraph's indentation inside a table cell?

Category: 
Tags: composite modetablescellParagraphiText 7
Cell in text mode, cell in composite mode
Cell in text mode, cell in composite mode

These paragraphs are also indented, but the problem is if a paragraph needs to take a new line due to text length, the indenting is not maintained on the new line, causing most of the text to be indented, then the remainder of the text containing no indenting on the new line.

Is there a way to determine if a paragraph will take a new line due to exceeding PdfPCell width, and to indent the remainder of the text if this is true?

Posted on StackOverflow on Jan 21, 2015 by jbailie1991

Please take a look at the SimpleTable4. In iText 7 there is only one possible way to add a paragraph into the cell.

Table table = new Table(1);
Paragraph right = new Paragraph("This is right, because we create a paragraph with an indentation to the left and as we are adding the paragraph in composite mode, all the properties of the paragraph are preserved.");
right.setMarginLeft(20);
Cell rightCell = new Cell().add(right);
table.addCell(rightCell);
doc.add(table);

This is the result:

Cell in composite mode
Cell in composite mode

The Paragraph is preserved. If an alignmentwas defined at the level of the Cell, it is ignored in favor of the alignment of the Paragraph. All the other properties that are defined at the level of the Paragraph are preserved.

Click this link if you want to see how to answer this question in iText 5.