itextSharp – html to pdf一些土耳其字符丢失

前端之家收集整理的这篇文章主要介绍了itextSharp – html to pdf一些土耳其字符丢失前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
当我尝试从HTML生成PDF时,一些土耳其字符如ĞÜŞİÖÇğüşıöç在PDF中缺失,我看到一个空格代替这些字符,但我想打印那个字符.

我的代码是:

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

如何在PDF上打印所有土耳其语字符?

解决方法

我终于找到了解决这个问题的方法,通过这个你可以打印所有的土耳其字符.
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));
原文链接:https://www.f2er.com/html/232127.html

猜你在找的HTML相关文章