iTextSharp& amp;阿拉伯语文本 [英] problem with iTextSharp & arabic text

查看:93
本文介绍了iTextSharp& amp;阿拉伯语文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有



现在阿拉伯语字符串根本没有显示在PDF中



i尝试过以下内容:



 string fontpath = Environment.GetEnvironmentVariable(SystemRoot)+\\fonts\\ times.ttf ; 
BaseFont basefont = BaseFont.CreateFont(fontpath,BaseFont.IDENTITY_H,true);
字体arabicFont = new iTextSharp.text.Font(basefont,24,iTextSharp.text.Font.NORMAL,iTextSharp.text.Color.BLUE);

table.RunDirection = PdfWriter.RUN_DIRECTION_RTL;





i尝试了很多其他字体

阿拉伯字母出现但是从左到右依次相反,每个字母都没有连接到相邻的字母



请帮助

谢谢

再见

解决方案

  public   void  PersianSupport( string  sFilePDF)
{
凭证凭证= new Document();
尝试
{
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(sFilePDF,FileMode.Create));
document.Open();
string fontpath = Environment.GetEnvironmentVariable( SystemRoot)+ \\fonts \\ times.ttf ;
BaseFont basefont = BaseFont.CreateFont(fontpath,BaseFont.IDENTITY_H, true );
iTextSharp.text.Font arabicFont = new iTextSharp.text.Font(basefont, 24 , iTextSharp.text.Font.NORMAL,iTextSharp.text.Color.BLUE);


var el = new Chunk();
iTextSharp.text.Font f2 = new iTextSharp.text.Font(basefont,el.Font.Size,
el.Font.Style, el.Font.Color);
el.Font = f2;
PdfPTable table = new PdfPTable( 1 );

table.RunDirection = PdfWriter.RUN_DIRECTION_RTL;

var str = نام:;
PdfPCell cell = new PdfPCell( new 短语( 10 ,str,el.Font));
table.AddCell(cell);

document.Add(table);
document.Close();

}
catch (DocumentException de)
{
// this.Message = de.Message;
}
catch (IOException ioe)
{
// this.Message = ioe.Message;
}

// 第5步:我们关闭文件
document.Close();


}


您好,



for多语言支持您可以查看以下链接中给出的示例代码

在PDF中显示中文字符by iTextSharp [ ^ ]

http://stackoverflow.com/questions/ 4930800 / create-pdf-from-persian-html-file-by-itextsharp [ ^ ]

并且关于逆序字符外观你的意思是从左到右?因为阿拉伯字符从右到左开始不像英语


http://engthunder.wordpress.com/2011/10/03/export-gridview-to-pdf-with-arabic-content-using-itextsharp/ [ ^ ]

dear all

now the arabic string does not displayed at all in the PDF

i tried the following :

 string fontpath = Environment.GetEnvironmentVariable("SystemRoot") + "\\fonts\\times.ttf";
BaseFont basefont = BaseFont.CreateFont(fontpath, BaseFont.IDENTITY_H, true);
Font arabicFont = new iTextSharp.text.Font(basefont, 24, iTextSharp.text.Font.NORMAL, iTextSharp.text.Color.BLUE);

table.RunDirection =PdfWriter.RUN_DIRECTION_RTL;



i tried many other fonts
the arabic letters appeared but in reverse order from left to right and every letter is alone not connected to the adjacent one

please help
thanks
bye

解决方案

public void PersianSupport(string sFilePDF)
        {
            Document document = new Document();
            try
            {
                PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(sFilePDF, FileMode.Create));
                document.Open();
                string fontpath = Environment.GetEnvironmentVariable("SystemRoot") + "\\fonts\\times.ttf";
                BaseFont basefont = BaseFont.CreateFont(fontpath, BaseFont.IDENTITY_H, true);
                iTextSharp.text.Font arabicFont = new iTextSharp.text.Font(basefont, 24, iTextSharp.text.Font.NORMAL, iTextSharp.text.Color.BLUE);


                var el = new Chunk();
                iTextSharp.text.Font f2 = new iTextSharp.text.Font(basefont, el.Font.Size,
                                                el.Font.Style, el.Font.Color);
                el.Font = f2;
                PdfPTable table = new PdfPTable(1);
                
                table.RunDirection = PdfWriter.RUN_DIRECTION_RTL;
                
                var str = "نام : " ;
                PdfPCell cell = new PdfPCell(new Phrase(10, str, el.Font));
                table.AddCell(cell);

                document.Add(table);
                document.Close();

            }
            catch (DocumentException de)
            {
  //              this.Message = de.Message;
            }
            catch (IOException ioe)
            {
//                this.Message = ioe.Message;
            }

            // step 5: we close the document
            document.Close();


        }


Hi,

for multilingual support you can check sample codes given at the links below
Display Chinese Characters in PDF created by iTextSharp[^]
http://stackoverflow.com/questions/4930800/create-pdf-from-persian-html-file-by-itextsharp[^]
and regarding reverse order character appearance did you mean left to right? because arabic character starts from right to left unlike English


http://engthunder.wordpress.com/2011/10/03/export-gridview-to-pdf-with-arabic-content-using-itextsharp/[^]


这篇关于iTextSharp& amp;阿拉伯语文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆