Please take a look at the SimpleTable4 example. In this example, I add an indented paragraph to a cell the wrong way (your way) and I add a paragraph to a cell the correct way (as explained in the documentation):
PdfPTable table = new PdfPTable(1);
Paragraph wrong = new Paragraph("This is wrong, because an object that was originally a paragraph is reduced to a phrase due to the fact that it's put into a cell that uses text mode.");
wrong.setIndentationLeft(20);
PdfPCell wrongCell = new PdfPCell(wrong);
table.addCell(wrongCell);
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.setIndentationLeft(20);
PdfPCell rightCell = new PdfPCell();
rightCell.addElement(right);
table.addCell(rightCell);
document.add(table);
This is the result:
In the first row, we no longer have a Paragraph
, we have a Phrase
that uses the alignment and the leading of the PdfPCell
.
In the second row, the Paragraph
is preserved. If an alignment or a leading was defined at the level of the PdfPCell
, it is ignored in favor of the alignment and the leading of the Paragraph
. All the other properties that are defined at the level of the Paragraph
(and that do not exist for Phrase
objects) are preserved.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…