c# - Arabic Text is not being shown while converting from html to pdf using iText# -


i have converted rtf string html string neccessary step show formatting along text. now, have converted html pdf using markuponverter liberary- 1 found @ codeproject. when open pdf file, shows english text formatting when try convert text written in arabic(or urdu being subset), no text there in pdf file after being converted pdf. reckoned font rendering problem , have tried changing fonts arialuni.ttf nothing happened. far have tried , going write snippet using here point @ mistakes , suggest tips.

richtextbox rtbnew = new richtextbox();         rtbnew.rtf = this.rtb.rtf;         string abc = this.markupconverter.convertrtftohtml(rtbnew.rtf);         messagebox.show(abc);         //rtbnew.text = this.rtb.text;         //string str = rtbnew.text;         //textreader tr = new stringreader(str);         document doc = new document();         pdfwriter writer = pdfwriter.getinstance(doc, new filestream(@path + "/doc2.pdf", filemode.create));         //////////////////         doc.open();          //sample html         stringbuilder stringbuilder = new stringbuilder();         stringbuilder.append(@"<?xml version=""1.0"" encoding=""utf-8""?>              <!doctype html                   public ""-//w3c//dtd xhtml 1.0 strict//en""                 ""http://www.w3.org/tr/xhtml1/dtd/xhtml1-strict.dtd"">              <html xmlns=""http://www.w3.org/1999/xhtml"" xml:lang=""en"" lang=""en"">                 <head>                     <title>minimal xhtml 1.0 document w3c dtd</title>                 </head>               <body> " + abc + "  </body></html>");          //path our font         string arialunitff = path.combine(environment.getfolderpath(environment.specialfolder.fonts), "arialuni.ttf");         //register font itextsharp         itextsharp.text.fontfactory.register(arialunitff);          //create new stylesheet         itextsharp.text.html.simpleparser.stylesheet st = new itextsharp.text.html.simpleparser.stylesheet();         //set default body font our registered font's internal name         st.loadtagstyle(htmltags.body, htmltags.face, "arial unicode ms");         //set default encoding support unicode characters         st.loadtagstyle(htmltags.body, htmltags.encoding, basefont.identity_h);          //parse our html using stylesheet created above         list<ielement> list = htmlworker.parsetolist(new stringreader(stringbuilder.tostring()), st);          //loop through each element, don't bother wrapping in p tags         foreach (var element in list)         {             messagebox.show(element.tostring());             doc.add(element);         }          doc.close(); 

this code shows english text , without formattign doesn't show arabic text not plain text.

question marks instead of characters mean wkhtmltopdf cannot find font arabic characters. fool-proof solution i've found base64-encode font, , include directly in css/style declaration:

@font-face {     font-family: 'amiri';     src: url(data:font/truetype;charset=utf-8;base64,<base64-encoded-data> } 

edit: step step instructions:

  1. visit this site.
  2. upload font encode binary file, press encode. encode file , generate encoded font. output bunch of random characters.
  3. copy css snippet above, , replace <base64-encoded-data> base64 output got encoding.
  4. add css snippet stylesheet, somewhere near top. it's important add before refer arialuni font in css code.
  5. now can declare html elements use font, would:
@font-face {     font-family: 'arialuni';     src: url(data:font/truetype;charset=utf-8;base64,aaeaaaataqa... } body, h1 {     font-family: 'arialuni', sans-serif; } 

Comments