span string mvc5 itextsharp

时间:2014-01-28 02:41:04

标签: c# asp.net-mvc itextsharp

我正在尝试使用以下方法将所选单词设为粗体:

 if (!string.IsNullOrEmpty(person)) completedby = "<span style='font-weight: bold'> Assessment completed by: </span>" + person +  "\n";
        chunk = new Chunk(completedby + "\n" +
        "", (font5));
        paragraph = new Paragraph();
        paragraph.Alignment = Element.ALIGN_LEFT;
        paragraph.Add(chunk);
        doc.Add(paragraph);

我在PDF文件中得到以下内容:

<span style='font-weight: bold'> Assessment completed by: </span>

任何建议,提前谢谢。

1 个答案:

答案 0 :(得分:0)

答案是使用HTMLWorker.ParseToList,如下所示:

string completedby = @"<span style='font-size:10;'>";

                if (!string.IsNullOrEmpty(person)) completedby += "<br/><br/>" + "<b>"+"completed by: " +"</b>" + person + ", RN" + "<br/>";

                completedby += "</span>";
                var reader1 = new StringReader(completedby);
                var htmlarraylist1 = HTMLWorker.ParseToList(reader1, null);

                //add the collection to the document
                foreach (IElement t in htmlarraylist1)
                {
                    paragraph.Add(t);
                }
                doc.Add(paragraph);

希望这可以帮助某人。