我正在使用iTextsharp tp創建PDF。我有以下幾行代碼在PDF上顯示文本。iTextsharp字符串之間的下劃線
var contentByte = pdfWriter.DirectContent;
contentByte.BeginText();
contentByte.SetFontAndSize(baseFont, 10);
var multiLine = " Request for grant of leave for ____2______days";
contentByte.ShowTextAligned(PdfContentByte.ALIGN_LEFT, multiLine, 100, 540, 0);
contentByte.EndText();
我需要用下劃線替換「____」。在下劃線「2」應顯示。
請幫我解決這個問題。
我解決了你的答案。感謝ü.. @克里斯·哈斯
var baseFont = BaseFont.CreateFont(fontFile, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
var mainFont = new iTextSharp.text.Font(baseFont, 10);
//Our Phrase will hold all of our chunks
var p = new Phrase();
//Add the start text
p.Add(new Chunk("Request for grant of leave for ", mainFont));
var space1 = new Chunk(" ", FontFactory.GetFont(FontFactory.HELVETICA, 12.0f, iTextSharp.text.Font.BOLD | iTextSharp.text.Font.UNDERLINE));
p.Add(space1);
//Add our underlined text
var c = new Chunk("2", mainFont);
c.SetUnderline(0.1f, -1f);
p.Add(c);
var space1 = new Chunk(" ", FontFactory.GetFont(FontFactory.HELVETICA, 12.0f, iTextSharp.text.Font.BOLD | iTextSharp.text.Font.UNDERLINE));
p.Add(space1);
//Add our end text
p.Add(new Chunk(" days", mainFont));
//Draw our formatted text
ColumnText.ShowTextAligned(pdfWriter.DirectContent, PdfContentByte.ALIGN_LEFT, p, 100, 540, 0);
請任何人都知道這??? – RUPA
您可以將html輸出用於在itextsharp中創建pdf。因此,在HTML中,你可以把標籤來完成 – Anabik