Html to pdf some characters are missing (itextsharp) in Asp.Net MVC Application -


i want export razor view pdf using itextsharp library. problem turkish characters such İ,ı,Ş,ş etc... missing in pdf document. code used export pdf is:

  public pdfactionresult(object model)     {         model = model;     }  public override void executeresult(controllercontext context)     {         iview viewengineresult;         viewcontext viewcontext;          if (viewname == null)         {             viewname = context.routedata.getrequiredstring("action");         }          context.controller.viewdata.model = model;           var workstream = new memorystream();         var document = new document();          pdfwriter writer = pdfwriter.getinstance(document, workstream);         writer.closestream = false;          document.open();          viewengineresult = viewengines.engines.findview(context, viewname, null).view;         var sb = new stringbuilder();         textwriter tr = new stringwriter(sb);          viewcontext = new viewcontext(context, viewengineresult, context.controller.viewdata,         context.controller.tempdata, tr);         viewengineresult.render(viewcontext, tr);          cultureinfo ci = new cultureinfo("az-latn-az");         encoding enc = encoding.getencoding(ci.textinfo.ansicodepage);          stream stream = new memorystream(enc.getbytes(sb.tostring()));          xmlworkerhelper.getinstance().parsexhtml(writer, document, stream, null);          document.close();          new filecontentresult(workstream.toarray(), "application/pdf").executeresult(context);     } } 

then access as:

 public actionresult studentpdf(guid studentid)     {         var model = _studentrepository.getbyidguid(studentid);          return new pdfactionresult(model);     } 

thanks reply

by way can print 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");   // give 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)); 

hope helps regards, vinit patel


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -