How to create a pdf file and write tamil letter using C#?

73 Views Asked by At

To create a pdf file using tamil word without any alignment issue and speeling mistake. using itextsharp dll. code below

string OutputPdffile = Path.Combine(pdfpath, language + "_" + DateTime.Now.ToString("ddMMyyyy_HHmmss")) + ".pdf";
using (System.IO.FileStream fs = new FileStream(OutputPdffile, FileMode.CreateNew))
{
    Document document = new Document(PageSize.A4, 25, 25, 30, 30);
    PdfWriter writer = PdfWriter.GetInstance(document, fs);
    // Add meta information to the document  
    document.AddAuthor("Micke Blomquist");
    document.AddCreator("Sample application using iTextSharp");
    document.AddKeywords("PDF tutorial education");
    document.AddSubject("Document subject - Describing the steps creating a PDF document");
    document.AddTitle("The document title - PDF creation using iTextSharp");
    // Open the document to enable you to write to the document  
    document.Open();
  
    if (language == "Tamil")
    {
        string fontpath = AppDomain.CurrentDomain.BaseDirectory + "/Fonts/Tamil/Nirmala.ttf";                       
        string fontpath1 = AppDomain.CurrentDomain.BaseDirectory + "/Fonts/Tamil/NotoSansTamil.ttf";                        
        BaseFont bf = BaseFont.CreateFont(fontpath, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
        BaseFont bf1 = BaseFont.CreateFont(fontpath1, BaseFont.IDENTITY_H , BaseFont.EMBEDDED);                       
        iTextSharp.text.Font font = new iTextSharp.text.Font(bf, 12);
        iTextSharp.text.Font font1 = new iTextSharp.text.Font(bf1, 12);                      

        // Add a simple and wellknown phrase to the document in a flow layout manner  
        document.Add(new Paragraph(PrintInTamil(content), font));
        
    }
    else
    {
        // Add a simple and wellknown phrase to the document in a flow layout manner  
        document.Add(new Paragraph(content));
    }
    
    // Close the document  
    document.Close();
    // Close the writer instance  
    writer.Close();
    // Always close open filehandles explicity  
    fs.Close(); 

I'm getting alignment and spelling mistake like that. error pdf image

I expected pdf file with tamil words without any alignment and spelling mistake in the pdf.

I expected pdf like

0

There are 0 best solutions below