Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
689 views
in Technique[技术] by (71.8m points)

itext - itextSharp - htmlString to pdf Unicode are missing

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 characters but i want to print that character.

My code is:

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

    }

please reply i need suggestion ... regards

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...