-1

I am try to create marathi PDF using iTextSharp PDF is created successfully but marathi text are improper

expecting result अंदाजपत्रकातील तरतूद व खर्च but getting data अंदाजपत् रकातील तरतुद व खरच

code

public void pdf() {
   string pdfFileName = Request.PhysicalApplicationPath + "\\PDF\\" + "GenerateHTMLTOPDF.pdf";
   FileStream fs = new FileStream(pdfFileName, FileMode.Create);
   Document doc = new Document(PageSize.LETTER);
   PdfWriter writer = PdfWriter.GetInstance(doc, fs);           
   doc.Open();
   //Path to our font            
   string mangalTff = Request.PhysicalApplicationPath + "\\font\\" + "mangal.ttf";
   //Register the font with iTextSharp
   iTextSharp.text.FontFactory.Register(mangalTff);
   //Create a new stylesheet
   iTextSharp.text.html.simpleparser.StyleSheet ST = new iTextSharp.text.html.simpleparser.StyleSheet();
   //Set the default body font to our registered font's internal name           
   ST.LoadTagStyle(HtmlTags.BODY, HtmlTags.FACE, "mangal");
   //Set the default encoding to support Unicode characters
   ST.LoadTagStyle(HtmlTags.BODY, HtmlTags.ENCODING, BaseFont.IDENTITY_H);           
   //Parse our HTML using the stylesheet created above
   string htmlDisplayText = Convert.ToString(HTMLReport());
   htmlDisplayText = Encoding.UTF8.GetString(ASCIIEncoding.Convert(Encoding.Unicode, Encoding.Unicode, Encoding.UTF8.GetBytes(htmlDisplayText)));// html 
   List<IElement> list = HTMLWorker.ParseToList(new StringReader(htmlDisplayText), ST);           
  //Loop through each element, don't bother wrapping in P tags
  foreach (var element in list){
      doc.Add(element);
  }
  doc.Close();
  Response.ContentType = "application/x-download";
  Response.AddHeader("Content-Disposition", string.Format("attachment; filename=\"{0}\"", "GenerateHTMLTOPDF.pdf"));
  Response.ContentEncoding = Encoding.UTF8;
  Response.WriteFile(pdfFileName);
  Response.HeaderEncoding = Encoding.UTF8;
  Response.Flush();
  Response.End();
 }

advance thank you

Puneet
  • 615
  • 2
  • 7
  • 17
  • https://stackoverflow.com/questions/9210833/itext-marathi-indian-language-display-issue This link suggests,**iText does not support the Devanāgarī writing system** – Prasad Telkikar Apr 02 '18 at 07:36
  • thank you i tried this one also still data is improper like मराठी ग् री टींग् स, मराठी शुभेच् छा पत् रे i use space to explain – pooja sankpal Apr 02 '18 at 07:56
  • 1
    @Prasadtelkikar That link is outdated. Recent version of iText support Devanagari (iText 7 + the pdfCalligraph add-on). – Bruno Lowagie Apr 02 '18 at 14:03

1 Answers1

1

iText 7 .NET, with the pdfCalligraph add-on, supports Devanagari, and many other writing systems. So you really need to upgrade. See https://itextpdf.com/itext7/pdfcalligraph for code examples and screenshots.

Additionally, please stop using HTMLWorker, it is incomplete, unsupported and obsolete. Use pdfHTML instead, which is another iText 7 add-on.

Amedee Van Gasse
  • 7,280
  • 5
  • 55
  • 101