小编Kat*_*ate的帖子

如何将富文本框(HTML)添加到表格单元格?

我有一个名为"DocumentContent"的富文本框,我将使用以下代码将其内容添加到pdf:

iTextSharp.text.Font font = FontFactory.GetFont(@"C:\Windows\Fonts\arial.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 12f, Font.NORMAL, BaseColor.BLACK);
            DocumentContent = System.Web.HttpUtility.HtmlDecode(DocumentContent);
            Chunk chunkContent = new Chunk(DocumentContent);
            chunkContent.Font = font;            

            Phrase PhraseContent = new Phrase(chunkContent);
            PhraseContent.Font = font;


            PdfPTable table = new PdfPTable(2);
            table.WidthPercentage = 100;
            PdfPCell cell;

            cell = new PdfPCell(new Phrase(PhraseContent));
            cell.Border = Rectangle.NO_BORDER;
            table.AddCell(cell);
Run Code Online (Sandbox Code Playgroud)

问题是当我打开PDF文件时,内容显示为HTML而不是文本,如下所示:

<p>Overview&#160; line1 </p><p>Overview&#160; line2
</p><p>Overview&#160; line3 </p><p>Overview&#160;
line4</p><p>Overview&#160; line4</p><p>Overview&#160;
line5&#160;</p>
Run Code Online (Sandbox Code Playgroud)

但它应该如下所示

Overview line1
Overview line2
Overview line3
Overview line4
Overview line4
Overview line5
Run Code Online (Sandbox Code Playgroud)

我要做的是保留用户应用于富文本的所有样式,只需将字体系列更改为Arial.

我可以更改字体系列,但我需要将此内容从HTML解码为文本.

您能否提一些建议?谢谢

pdf itextsharp richtext

4
推荐指数
1
解决办法
3515
查看次数

标签 统计

itextsharp ×1

pdf ×1

richtext ×1