itextSharp - html to pdf some turkish characters are missing

后端 未结 3 517
清酒与你
清酒与你 2020-12-10 22:51

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 characte

3条回答
  •  余生分开走
    2020-12-10 23:41

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

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

提交回复
热议问题