How to underline text using PdfContentByte in itextsharp

This actually refers to a question that is actually closed.

Iam using ItextSharp 5.2.1.

I want the header text to be underlined using PdfContentByte. Please provide me a solution.

+5
source share
1 answer
private PdfContentByte pdfContentByte;



 private string DescriptionToPrint="Hii!! I will be underlined."
  private Int32  AlignmentofDescription = 3;
  private float  XofDescription = 110;
  private float  YofDescription = 440;
  private float  RotationofDescription = 0; 

for writing pdf using pdfcontentbyte we usually use the following

(start of text & end of text)

format

pdfContentByte.BeginText();
    pdfContentByte.ShowTextAligned(PdfContentByte.ALIGN_LEFT, DescriptionToPrint.ToString(), XofDescription, YofDescription, RotationofDescription);
    pdfContentByte.EndText();

There is also an alternative to the above technique, which is also quiet.

This is if you want the same formatting that you applied to pdfcontentbyteusingBaseFont

//ColumnText.ShowTextAligned(pdfContentByte, Element.ALIGN_LEFT, new Phrase(DescriptionToPrint), XofDescription, YofDescription, RotationofDescription);

If you want to emphasize text, in PhraseplaceChunk

  ColumnText.ShowTextAligned(pdfContentByte, Element.ALIGN_LEFT, new Phrase(new Chunk(DescriptionToPrint.ToString(), FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.UNDERLINE))), XofDescription, YofDescription, RotationofDescription);

.

new Phrase(new Chunk(DescriptionToPrint.ToString(), FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.UNDERLINE)))

ColumnText , new Phrase, , base font .

Phrase Chunk .

, Chunk

float (20.25) "20.25f" , ...

+6

All Articles