Saravanan Saravanan - 1 year ago 399
ASP.NET (C#) Question

How to Create PDF file with Tamil Font by using itextsharp in C#?

we are creating pdf files in our C# application by passing TAMIL text(one of the indian language).So, I already installed AVVAIYAR.TTF(one of the tamil font) font for my tamil language font.But when i run the below mentioned pgm, the created pdf file does not contain any tamil font display.It shows empty lines instead of the tamil text...

C# Code:

Document document = new Document();
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(@"C:\pdfout.pdf", FileMode.Create));

PdfContentByte pcb = writer.DirectContent;
Font ft = new Font();
FontFactory.Register(@"C:\WINDOWS\Fonts\AVVAIYAR.TTF", "AVVAIYAR");
ft = FontFactory.GetFont("AVVAIYAR");

Paragraph pr1 = new Paragraph("இது முதல் பேரா", ft);
Paragraph pr2 = new Paragraph("This is a Sub Paragraph");
Paragraph pr3 = new Paragraph("This is the Second Paragraph");


my output pdf file is :

<blank line>
This is a Sub Paragraph
This is the Second Paragraph

And also i have to support some more indian languages to create the PDF files.

Answer Source

I have put a reference to ARIALUNI.TTF.I tried like this,

string fontpath = Environment.GetEnvironmentVariable("SystemRoot") + "\\fonts\\ARIALUNI.TTF"; 
BaseFont basefont = BaseFont.CreateFont(fontpath, BaseFont.IDENTITY_H, true);
Font font = new iTextSharp.text.Font(basefont, 24, iTextSharp.text.Font.NORMAL, iTextSharp.text.Color.BLUE);
Paragraph pr1 = new Paragraph("இது முதல் பேரா", AVVAIYARFont);

So, now tamil font is displayed in the pdf file.But simple simple spelling mistake... so i am doing some read on that issue...

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download