2

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));
document.Open();

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");

document.Add(pr1);
document.Add(pr2);
document.Add(pr3);
document.Close();

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.

Alexis Pigeon
  • 7,423
  • 11
  • 39
  • 44
Saravanan
  • 11,372
  • 43
  • 143
  • 213

4 Answers4

1

Can you please try the following code snippet?

string fontpath = Environment.GetEnvironmentVariable("SystemRoot") + "\\fonts\\AVVAIYAR.TTF";
BaseFont basefont = BaseFont.CreateFont(fontpath, BaseFont.IDENTITY_H, true);
Font AVVAIYARFont = new iTextSharp.text.Font(basefont, 24, iTextSharp.text.Font.NORMAL, iTextSharp.text.Color.BLUE); /*For test color blue is placed with some foramtting.*/

Paragraph pr1 = new Paragraph("இது முதல் பேரா", AVVAIYARFont);

This should work...

An out of the box thought, iText has not full support for all the indic languages at moment...See here they say that they dont have enough volunteers to support this.

Jigar Pandya
  • 6,004
  • 2
  • 27
  • 45
  • But i put like this, Paragraph pr1 = new Paragraph("english", AVVAIYARFont); instead of tamil input, i have passed english input, then it is created some text in tamil not meaningfully... – Saravanan Sep 18 '12 at 06:39
  • have you checked the out of the box comment? – Jigar Pandya Sep 18 '12 at 06:46
  • :I have put a reference to ARIALUNI.TTF.I tried like this, string fontpath = Environment.GetEnvironmentVariable("SystemRoot") + "\\fonts\\ARIALUNI.TTF"; So, now tamil font is displayed in the pdf file.But simple simple spelling mistake... so i am doing some read on that issue... – Saravanan Sep 20 '12 at 03:25
  • Great so does that mean when you put both ARIALUNI.TTF + AVVAIYAR.TTF in logic it works. Right? – Jigar Pandya Sep 21 '12 at 04:45
  • No, i just put Arialuni.TTF only...dont care about avvaiyar.ttf – Saravanan Sep 21 '12 at 05:07
  • Ok so let's say you need to Generate user filled form (user filled form in TAMIL so will this work???) please put answer here so it would help to other as well.. – Jigar Pandya Sep 21 '12 at 05:19
1

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...

Saravanan
  • 11,372
  • 43
  • 143
  • 213
1

Procees 1:

step 1:Go to http://software.nhm.in/services/converter website

step2:paste this word படிவம்-டி ஊதியம் சீட்டு /விடுப்பு அட்டை

step3:1.change the first drop down to Unicode , 2.change the second drop down to TAB

step5:click the button converter

step6.text will be alligned.

step 7:main process start from hear

1.change the second drop down to TSCII and click on convert.(dont panic no changes would exists)

2.now change the first drop down to Unicode automatticaly the tamil text would change to "ÀÊÅõ-Ê °¾¢Âõ º£ðÎ /Å¢ÎôÒ «ð¨¼";

3.copy the content and place it in notepad.

Process 2:

1.First download TSC-Sri.ttf(http://www.eaglefonts.com/download.php?action=zip&image_id=129859)

2.save or move it in c:\Windows\fonts

3.finally Pate the below code in the c# program

     string fontpath = Environment.GetEnvironmentVariable("SystemRoot") + "\\fonts\\TSC-Sri.ttf";
    BaseFont basefont = BaseFont.CreateFont(fontpath, BaseFont.IDENTITY_H, true);
    iTextSharp.text.Font font = new iTextSharp.text.Font(basefont, 24, iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.BLUE);
    Paragraph pr1 = new Paragraph("ÀÊÅõ-Ê °¾¢Âõ º£ðÎ /Å¢ÎôÒ «ð¨¼ ", font);

4.run the itextsharp pdf program output as excepted 100% working.

0

A viable alternative is Quest PDF.

using QuestPDF.Fluent;
using QuestPDF.Helpers;
using QuestPDF.Infrastructure;

Document.Create(container =>
{
    container.Page(page =>
    {
        page.Size(PageSizes.A4);
        page.Margin(2, Unit.Centimetre);
        page.PageColor(Colors.White);
        page.DefaultTextStyle(x => x.FontSize(20));
        page.DefaultTextStyle(x => x.FontFamily("Vijaya"));
        
        page.Header()
            .Text("தமிழ் PDF!")
            .SemiBold().FontSize(36).FontColor(Colors.Blue.Medium);
        
        page.Content()
            .PaddingVertical(1, Unit.Centimetre)
            .Column(x =>
            {
                x.Spacing(20);
                
                x.Item().Text("தமிழ் (Tamil language) தமிழர்களினதும் தமிழ் பேசும் பலரின் தாய்மொழி ஆகும். தமிழ், உலகின் உள்ள முதன்மையான மொழிகளில் ஒன்றும் செம்மொழியும் ஆகும்.");                
            });
        
        page.Footer()
            .AlignCenter()
            .Text(x =>
            {
                x.Span("பக்கம் ");
                x.CurrentPageNumber();
            });
    });
})
.GeneratePdf("தமிழ்.pdf");