0

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

ERROR

i need to use //2// for generating UNDERLINE which is not supported in BaseFont of iTextsharp

Please Help!!

2
  • FWIW - there is no underlined text in PDF. Underlines are made by drawing an actual line. Commented Sep 10, 2013 at 14:34
  • 1
    ColumnText.ShowTextAligned calls SaveState, BeginText etc. itself. Thus, don't start a text object yourself when using it. Commented Sep 10, 2013 at 14:40

1 Answer 1

2

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).

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.