当我尝试从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));