Reputation: 227
I am Creating a PDF using ItextSharp 5.0.5
Used follwing Code
1)
var _with1 = underContent;
_with1.SaveState();
_with1.SetGState(gstate);
_with1.SetColorFill(color);
_with1.BeginText();
_with1.SetFontAndSize(font, txt_Font2);
_with1.SetTextMatrix(30, 30);
//**1**//
_with1.ShowTextAligned(Element.ALIGN_CENTER, watermarkText, txt_X2, txt_Y2, txt_Rotat2);
//**1**//
_with1.EndText();
_with1.RestoreState();
2)
//**2**//
ColumnText.ShowTextAligned(_with1, Element.ALIGN_CENTER, new Phrase(new Chunk(watermarkText, FontFactory.GetFont(@"C:\WINDOWS\Fonts\" + FntNm + ".TTF", txt_Font2, 0))), txt_X2, txt_Y2, txt_Rotat2);
//**2**//
Replacing //**1**//
with //**2**//
i am getting Following Error
i need to use //2// for generating UNDERLINE which is not supported in BaseFont of iTextsharp
Please Help!!
Upvotes: 0
Views: 229
Reputation: 77586
You are nesting text objects! That's illegal. More recent iTextSharp versions warn you about this problem.
Bottom line: you need to remove at least the following lines:
_with1.BeginText();
_with1.SetFontAndSize(font, txt_Font2);
_with1.SetTextMatrix(30, 30);
_with1.EndText();
The whole idea of using the ColumnText
method is that you don't have to worry about creating the text object yourself (as explained in Chapter 3 of my book).
Upvotes: 2