我有一个名为"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  line1 </p><p>Overview  line2
</p><p>Overview  line3 </p><p>Overview 
line4</p><p>Overview  line4</p><p>Overview 
line5 </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解码为文本.
您能否提一些建议?谢谢