gpt4 book ai didi

itextSharp - htmlString 到 pdf Unicode 丢失

转载 作者:行者123 更新时间:2023-12-05 01:05:22 28 4
gpt4 key购买 nike

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

}

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

最佳答案

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

    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 丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21423993/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com