itextSharp - html 到 pdf 缺少一些土耳其语字符

标签 itextsharp

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

关于itextSharp - html 到 pdf 缺少一些土耳其语字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21397331/

相关文章:

c# - MVC3将多个pdf作为zip文件返回

itextsharp - 使用 PDF itextSharp 可以在创建 pdf 文档时将图像放在文本之上

c# - 获取 ITextSharp 中支持的字体列表

c# - 使用 iTextSharp 获取 PDF 页面大小

c# - 默认参数 PageSize A4 C# 使用 itextsharp

c# - 使用 C# 使用 iTextsharp 突出显示现有 PDF 的文本(颜色)

pdf - 如何将富文本框 (HTML) 添加到表格单元格?

c# - 使用 itextsharp(或任何 c# pdf 库),如何打开 PDF、替换一些文本并再次保存?

itextsharp - 带圆角的 table

c# - 如何获取 XFA 表单中的字段列表?