HtmlForm form = new HtmlForm(); string imagepath = Server.MapPath("img"); form.Controls.Add(GroupingGridView1); StringWriter sw = new StringWriter(); Response.ContentEncoding = System.Text.Encoding.UTF8; HtmlTextWriter hTextWriter = new HtmlTextWriter(sw); form.Controls[0].RenderControl(hTextWriter); string html = HttpUtility.HtmlDecode(sw.ToString()); string pathHTML = "c:\\test.html"; StreamWriter filehtml = new System.IO.StreamWriter(pathHTML); filehtml.Write(html); filehtml.Dispose(); Document Doc = new Document(PageSize.A4); string Path = Environment.GetFolderPath (Environment.SpecialFolder.Desktop) + "\\baocao.pdf"; PdfWriter.GetInstance (Doc, new FileStream(Path, FileMode.Create)); Doc.Open(); iTextSharp.text.Image clogo = iTextSharp.text.Image.GetInstance(imagepath + "/slogo.jpg"); clogo.Alignment = iTextSharp.text.Image.ALIGN_LEFT; BaseFont bf = BaseFont.CreateFont(@"C:\WINDOWS\Fonts\TIMES.TTF", BaseFont.IDENTITY_H, true); iTextSharp.text.Font fonttitle = new iTextSharp.text.Font(bf, 15); iTextSharp.text.Font font = new iTextSharp.text.Font(bf, 10); iTextSharp.text.Font fonttext = new iTextSharp.text.Font(bf, 12); Paragraph header = new Paragraph(); header.Alignment = Element.ALIGN_CENTER; Paragraph text = new Paragraph(); Chunk c1 = new Chunk("Báo cáo thống kê thiết bị \n", fonttitle); Chunk c2 = new Chunk(DateTime.Now.ToShortDateString() + "\n\n", font); header.Add(c1); header.Add(c2); Doc.Add(clogo); Doc.Add(header); List<IElement> objects; var stream = new StreamReader(pathHTML, Encoding.UTF8);//.ReadToEnd(); objects = iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(stream, new StyleSheet()); Doc.NewPage(); for (int k = 0; k < objects.Count; k++) { PdfPTable table = new PdfPTable(1); table.RunDirection = PdfWriter.RUN_DIRECTION_RTL; var els = (IElement)objects[k]; //i can not add UNICODE when I ADD to DOCUMENT Doc.Add((IElement)objects[k]); } stream.Dispose(); Doc.Close(); Response.ClearContent(); Response.ClearHeaders(); Response.ContentType = "application/pdf"; Response.AddHeader ("Content-Disposition", "attachment; filename=" + strS); Response.TransmitFile(strS); Response.End(); //Response.WriteFile(strS); Response.Flush(); Response.Clear();
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)