iTextSharp: which alignment properties are used in a PdfPCell?

爱⌒轻易说出口 提交于 2019-12-01 18:01:06

You are confusing text mode with composite mode.

In the first code snippet, you work in text mode. This means that the content of the cell is considered to be text only and the properties of the cell are respected, whereas the properties of the elements added to the cell are ignored.

In the second code snippet, you work in composite mode. A cell switches to composite mode the moment you use the AddElement() method. In this case, the properties of the cell are ignored. Instead the properties of the elements is used.

For instance: in text mode, the content of the cell can only have one type of alignment. In composite mode, you can have a paragraph that is left aligned, a paragraph that is centered, and a paragraph that is right aligned, all in the same cell.

user2506112

Now yes, it worked.

PdfPCell cell1 = new PdfPCell();
Paragraph p1 = new Paragraph("Text 1", Font);
p1.Alignment = Element.ALIGN_RIGHT;
Paragraph p2 = new Paragraph("Text 2", Font);
p2.Alignment = Element.ALIGN_RIGHT;

cell1.AddElement(p1);
cell1.AddElement(p2);

Thank you.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!