itextSharp - 缺少htmlString到pdf Unicode [英] itextSharp - htmlString to pdf Unicode are missing

查看:87
本文介绍了itextSharp - 缺少htmlString到pdf Unicode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试从HTML生成PDF时,PDF中缺少一些土耳其字符,如ĞÜŞİÖÇ ğüşıöç我看到一个空格代替这些字符,但我想打印那个字符。

When I am trying to generate PDF from HTML, some Turkish characters like ĞÜŞİÖÇ ğüşıöç are missing in PDF, I see a space in place of these characters but i want to print that character.

我的代码是:

 public virtual void print pdf(string html, int id)
    {

    String htmlText = html.ToString();

    Document document = new Document();

    string filePath = HostingEnvironment.MapPath("~/Content/Pdf/");

    PdfWriter.GetInstance(document, new FileStream(filePath + "\\pdf-"+id+".pdf", 
    FileMode.Create));

    document.Open();

    iTextSharp.text.html.simpleparser.HTMLWorker hw =

                     new iTextSharp.text.html.simpleparser.HTMLWorker(document);



    hw.Parse(new StringReader(htmlText));

    document.Close();

    }

请回复我需要建议
...
问候

please reply i need suggestion ... regards

推荐答案

我终于找到了解决这个问题的方法,你可以打印所有土耳其字符。

I have finally find a solution for this problem, by this you can print all Turkish characters.

    String htmlText = html.ToString();

    Document document = new Document();

    string filePath = HostingEnvironment.MapPath("~/Content/Pdf/");
    PdfWriter.GetInstance(document, new FileStream(filePath + "\\pdf-"+Name+".pdf", FileMode.Create));
    document.Open();

    iTextSharp.text.html.simpleparser.HTMLWorker hw = new iTextSharp.text.html.simpleparser.HTMLWorker(document);
    FontFactory.Register(Path.Combine(_webHelper.MapPath("~/App_Data/Pdf/arial.ttf")),  "Garamond");   // just give a path of arial.ttf 
    StyleSheet css = new StyleSheet();
    css.LoadTagStyle("body", "face", "Garamond");
    css.LoadTagStyle("body", "encoding", "Identity-H");
    css.LoadTagStyle("body", "size", "12pt");

    hw.SetStyleSheet(css);

    hw.Parse(new StringReader(htmlText));

这篇关于itextSharp - 缺少htmlString到pdf Unicode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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