Home > Net >  The GridView export PDF with itextsharp, just can't show Chinese, a great god for answers
The GridView export PDF with itextsharp, just can't show Chinese, a great god for answers

Time:10-07

Protected void ExportToPDF_Click (object sender, EventArgs e)
{
The Response. The Clear ();

The Response. The Charset="GB2312";

StringBuilder sb=new StringBuilder();

StringWriter sw=new StringWriter (sb);

HtmlTextWriter HTW=new HtmlTextWriter (sw);



The Response. ContentType="application/PDF";

The Response. AddHeader (" the content - the disposition ", "legislation; Filename=MypdfFile. PDF ");

Response. ContentEncoding=System. Text. Encoding. Unicode;



The Document Document=new Document ();

PdfWriter. GetInstance (document, the Response OutputStream);

Document. The Open ();

BaseFont font=BaseFont. CreateFont (@ "C:/WINDOWS/Fonts/simhei. The vera.ttf", BaseFont. IDENTITY_H, BaseFont. NOT_EMBEDDED);

GvCustomers. RenderControl (HTW);

A string of HTML=sb. ToString ();

XmlTextReader reader=new XmlTextReader (new StringReader (HTML));

HtmlParser. Parse (document, reader);

Document. The Close ();
Sw. The Close ();

The Response. The Flush ();

The Response. The End ();
}
  •  Tags:  
  • C#
  • Related