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

只谈情不闲聊 提交于 2019-12-11 13:03:39

问题


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.


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




回答2:


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




回答3:


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.



来源:https://stackoverflow.com/questions/12471136/how-to-create-pdf-file-with-tamil-font-by-using-itextsharp-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!