itext ColumnText ignores alignment

怎甘沉沦 提交于 2019-11-28 01:42:48

Please google for the concepts "text mode" and "composite mode" or read chapter 3 of my book.

If you work in text mode, you can define the alignment at the level of the ColumnText object. In other words ct.Alignment = Element.ALIGN_RIGHT; will work in text mode.

If you work in composite mode, the alignment at the column level will be ignored in favor of the alignment of the elements added to the column. In your case, iText will ignore the ALIGN_RIGHT in favor of the alignment of the Paragraph objects added to the column. Looking at your code, I see that you didn't define an alignment for the paragraphs, so the default alignment ALIGN_LEFT is used.

How do you know if you're working in text mode or in composite mode? By default, ColumnText uses text mode but it switches to composite mode (removing all previously added text) the moment you invoke the AddElement() method.

As explained in chapter 4 of my book, text mode and composite mode also applies to PdfPCell.

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