Hi
string data i want to convert pdf kannda laguage convertion not working any body please help i am using this bellow code english working
StringReader sr = new StringReader(sb.ToString());
// StringReader sr = new StringReader(textConvert(sb.ToString()));
byte[] bytes = null;
iTextSharp.text.Document pdfDoc = new iTextSharp.text.Document(PageSize.A4, 10f, 10f, 10f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
//htmlparser.Parse(pdfDoc, Encoding.UTF8, new UnicodeFontFactory());
using (MemoryStream memoryStream = new MemoryStream())
{
iTextSharp.text.pdf.PdfWriter writer = iTextSharp.text.pdf.PdfWriter.GetInstance(pdfDoc, memoryStream);
//if (Session["lang"].ToString() == "Kannada")
//{
// Encoding encFrom = Encoding.UTF8;
// Encoding encTo = Encoding.UTF8;
// bytes = encFrom.GetBytes(sr.ToString());
//}
pdfDoc.Open();
// htmlparser.Parse(sr,Encoding.UTF8, new UnicodeFontFactory());
htmlparser.Parse(sr);
pdfDoc.Close();
bytes = memoryStream.ToArray();
Session["pdfbeforeesign"] = bytes;
memoryStream.Close();
}
Mohammad HussainPosted Aug 4, 2023, 1:14 PM
To handle Kannada font conversion in iTextSharp for PDF generation, you need to ensure that the font used for rendering Kannada characters is available and properly embedded in the PDF. Here's a step-by-step guide to achieve this:
Download the Kannada font: First, you need to download the appropriate Kannada font that you want to use in your PDF. Ensure that the font supports Unicode and includes all the required characters.
Add the font to your project: Once you have the Kannada font file, add it to your project's font folder or any other suitable location.
Use the font in iTextSharp: Now, you need to create a custom font object using the Kannada font file and register it with iTextSharp. You can do this using the
BaseFont.CreateFontmethod. Make sure to set the encoding asBaseFont.IDENTITY_Hto handle Unicode characters.Here's an example of how you can modify your code to include the Kannada font:
Replace
"path/to/kannada_font.ttf"with the actual path to your Kannada font file.