使用大块时则返回true iTextSharp的 [英] Return true when chunk is used iTextSharp
问题描述
我用大块尝试大胆的我的字体。但特别的是,我的标签,但在addcell下一个DataReader中写的。
这是我如何试图对我的DataReader内格式化我的标签
table.AddCell(phrase.Add(新组块(测试,normalFont))+ DR [0]的ToString());
这是声明短语和字体类型:
VAR normalFont = FontFactory.GetFont(FontFactory.HELVETICA,12);
VAR短语=新词();
这是正在显示的内容:
但是之前,我试图格式化我的标签这是怎么看起来像
这是我只需直接添加一个标签到我的 table.AddCell
table.AddCell(DR [0]的ToString());
您传递
phrase.Add(新组块(测试,normalFont))+ DR [0]的ToString()
到 table.AddCell
。过载 Phrase.Add
这里使用被声明为
public虚拟新布尔添加(IElement元)
的(CF <一个href=\"http://sourceforge.net/p/itextsharp/$c$c/HEAD/tree/trunk/src/core/iTextSharp/text/Phrase.cs#l297\"相对=nofollow> Phrase.cs )的
块引用>因此,
phrase.Add(新组块(测试,normalFont))
计算结果为布尔值真正
你有真+ DR [0]的ToString()
现在布尔被转换为
字符串
本身:真+ DR [0]的ToString()
在你的情况
D R [0]的ToString()
似乎包含管理员
。所以:真+管理员
从今往后:
Trueadmin
和,因为这
字符串
传递给table.AddCell
,你得到你所看到的。
相反,你可能想要做的线沿线的东西:
phrase.Add(新组块(测试,normalFont));
phrase.Add(DR [0]的ToString());
table.AddCell(短语);I'm trying to bold my font by using chunk. But the special thing is that my label is written under the addcell within a datareader.
This is how i attempt to format my label within my datareader
table.AddCell(phrase.Add(new Chunk("test:", normalFont)) + dr[0].ToString());
This is the declaration to phrase and font type:
var normalFont = FontFactory.GetFont(FontFactory.HELVETICA, 12); var phrase = new Phrase();
And this is what is being displayed:
However before i attempt to format my label this is how it will look like
This is where i just directly add a label into my
table.AddCell
table.AddCell(dr[0].ToString());
解决方案You pass
phrase.Add(new Chunk("test:", normalFont)) + dr[0].ToString()
to
table.AddCell
. The overload ofPhrase.Add
used here is declared aspublic virtual new bool Add(IElement element)
(cf. Phrase.cs)
Thus,
phrase.Add(new Chunk("test:", normalFont))
evaluates to the boolean valuetrue
and you havetrue + dr[0].ToString()
Now the boolean is converted to a
string
itself:"True" + dr[0].ToString()
In your case
dr[0].ToString()
seems to contain"admin"
. So:"True" + "admin"
Henceforth:
"Trueadmin"
And as this
string
is passed totable.AddCell
, you get what you see.Instead you might want to do something along the lines of:
phrase.Add(new Chunk("test:", normalFont)); phrase.Add(dr[0].ToString()); table.AddCell(phrase);
这篇关于使用大块时则返回true iTextSharp的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!