问题
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());
回答1:
You pass
phrase.Add(new Chunk("test:", normalFont)) + dr[0].ToString()
to table.AddCell
. The overload of Phrase.Add
used here is declared as
public virtual new bool Add(IElement element)
(cf. Phrase.cs)
Thus, phrase.Add(new Chunk("test:", normalFont))
evaluates to the boolean value true
and you have
true + 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 to table.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);
来源:https://stackoverflow.com/questions/16952771/return-true-when-chunk-is-used-itextsharp