iText的ColumnText忽略对齐 [英] itext ColumnText ignores alignment

查看:1232
本文介绍了iText的ColumnText忽略对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让右侧左侧的文字和一些某些行。
出于某种原因,iText的似乎完全忽略对齐。

I'm trying to get some rows of text on the left side and some on the right side. For some reason iText seems to ignore the alignment entirely.

例如:

// create 200x100 column
ct = new ColumnText(writer.DirectContent);
ct.SetSimpleColumn(0, 0, 200, 100);
ct.AddElement(new Paragraph("entry1"));
ct.AddElement(new Paragraph("entry2"));
ct.AddElement(new Paragraph("entry3"));
ret = ct.Go();

ct.SetSimpleColumn(0, 0, 200, 100);
ct.Alignment = Element.ALIGN_RIGHT;
ct.AddElement(new Paragraph("entry4"));
ct.AddElement(new Paragraph("entry5"));
ct.AddElement(new Paragraph("entry6"));
ret = ct.Go();

我已经设置了2列到Element.ALIGN_RIGHT的对齐方式,但文本显示印在一列之上,呈现不可读的文本。像排列仍设置为left。

I've set the alignment of the 2nd column to Element.ALIGN_RIGHT but the text appears printed on top of column one, rendering unreadable text. Like the alignment was still set to left.

任何想法?

推荐答案

请谷歌的概念的文本模式的和的复合模式的或读到的第3章我的书

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

如果你在工作的文本模式上,您可以在 Col​​umnText 对象的级别定义的对齐方式。换句话说 ct.Alignment = Element.ALIGN_RIGHT; 将在文本模式下工作。

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.

如果您在复合模式后,在列级校准将有利于加列元素的排列可以忽略工作。根据你的情况,iText的将有利于段落的对齐方式的忽略 ALIGN_RIGHT 对象添加到列。看着你code,我看到你没有定义的段落的对齐,所以默认对齐 ALIGN_LEFT 被使用。

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.

你怎么知道,如果你在工作的文本模式的或的复合模式的?默认情况下, Col​​umnText 使用的文本模式的,但它切换到的复合模式的(删除所有previously添加文本)此刻你调用的addElement()方法。

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.

由于在我的书的第四章解释,的文本模式的和的复合模式的也适用于 PdfPCell

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

这篇关于iText的ColumnText忽略对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆