public static bool ToPdf(DataTable dt, string filepath, string fileName) { Document document = new Document(); PdfWriter.GetInstance(document, new FileStream(filepath + fileName, FileMode.Create)); document.Open(); BaseFont bfChinese = BaseFont.CreateFont("C:\\WINDOWS\\Fonts\\simsun.ttc,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); iTextSharp.text.Font fontChinese = new iTextSharp.text.Font(bfChinese, 12, iTextSharp.text.Font.NORMAL, Color.BLACK); PdfPTable table = new PdfPTable(dt.Columns.Count); for (int i = 0; i < dt.Rows.Count; i++) { if (i == 0) { for (int j = 0; j < dt.Columns.Count; j++) { table.AddCell(new Phrase(dt.Columns[j].ToString(), fontChinese)); } } for (int j = 0; j < dt.Columns.Count; j++) { table.AddCell(new Phrase(dt.Rows[i][j].ToString(), fontChinese)); } } document.Add(table); document.Close(); return true; }
,