Html表导出为PDF,iTextSharp库中文字符未显示

时间:2016-06-04 09:11:50

标签: asp.net pdf export itextsharp

我正在使用stringbuilder在codebehind上创建动态html表。但是当我将html表导出为pdf时,中文字符列如下图所示为空白而不包括样式。

目前我的pdf输出是: enter image description here

和html表是: enter image description here 我该如何解决

我的代码是:

Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=TestPage.pdf");
Response.Charset = "UTF-8";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
this.Page.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();

0 个答案:

没有答案