ITEXTSHARP中的UNICODE字符问题! [英] Problem UNICODE characterers IN ITEXTSHARP !

查看:105
本文介绍了ITEXTSHARP中的UNICODE字符问题!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好!我的项目遇到有关Unicode char的问题!请帮我!

Hi there ! i got a problem with my project about Unicode char ! plzz help me !

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();

推荐答案

尝试更改字体,看一下:http://www.mikesdotnetting.com/Article/81/iTextSharp-Working-with-Fonts [
Try changing your font, look at this : http://www.mikesdotnetting.com/Article/81/iTextSharp-Working-with-Fonts[^]


这篇关于ITEXTSHARP中的UNICODE字符问题!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆