阿拉伯语在itextsharp编码 [英] arabic encoding in itextsharp

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

问题描述

当我试图此代码创建一个使用C#在阿拉伯语PDF,生成的PDF文件包含离散的字符。任何帮助,所以我不能得到连续的字符?



  //创建我们的文档对象
文档文件=新的文件(PageSize.LETTER);

//使用我们的文件流
(的FileStream FS =新的FileStream(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop)的test.pdf)的FileMode。创建,FileAccess.Write,FileShare.Read))
{
//绑定PDF作家文档和流
PdfWriter作家= PdfWriter.GetInstance(DOC,FS);写作
Doc.Open

//打开文件();

//添加页面
Doc.NewPage();

//的完整路径的Unicode文件宋体
串ARIALUNI_TFF = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts),arabtype.TTF);

//创建一个基本字体对象,并确保指定Identity-H
BASEFONT BF = BaseFont.CreateFont(ARIALUNI_TFF,BaseFont.IDENTITY_H,BaseFont.NOT_EMBEDDED);

//创建一个特定的字体对象
iTextSharp.text.Font F =新iTextSharp.text.Font(BF,12,iTextSharp.text.Font.NORMAL);

//写一些文字,最后一个字符是0x0278 - 拉丁小信披
Doc.Add(新词(这是一个ميسوɸ,F));

//写一些文字,最后一个字符是0x0682 - 带两个点以上垂直$ B $阿拉伯语字母HAH b Doc.Add(新词(Hello\\\ڂ,F)) ;

//关闭PDF
Doc.Close();
}


解决方案

从右至左书写和阿拉伯语的连字只支持 ColumnText PdfPTable



看看下面的例子:





阅读从中提取这些例子中找出为什么不是所有的话都在peace.pdf正确呈现的书



搜索的 http://tinyurl.com/itextsharpIIA2C11 对这些例子相应的C#版本。



在任何情况下,你需要知道如何显示阿拉伯语字形字体:

  BASEFONT BF = BaseFont.CreateFont(ARIALUNI_TFF,BaseFont.IDENTITY_H,BASEFONT。嵌入式); 
字体F =新的字体(BF,12);

您现在可以在表中添加阿拉伯语的文字,例如:

  PdfPCell电池=新PdfPCell(); 
cell.AddElement(新词(Hello\\\ڂ,F));
cell.RunDirection = PdfWriter.RUN_DIRECTION_RTL;


When I'm trying this code to create a PDF in Arabic using C#, the generated PDF file contains discrete characters. Any help so I can't get continuous characters?

//Create our document object
Document Doc = new Document(PageSize.LETTER);

//Create our file stream
using (FileStream fs = new FileStream(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Test.pdf"), FileMode.Create, FileAccess.Write, FileShare.Read))
{
    //Bind PDF writer to document and stream
    PdfWriter writer = PdfWriter.GetInstance(Doc, fs);

    //Open document for writing
    Doc.Open();

    //Add a page
    Doc.NewPage();

    //Full path to the Unicode Arial file
    string ARIALUNI_TFF = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "arabtype.TTF");

    //Create a base font object making sure to specify IDENTITY-H
    BaseFont bf = BaseFont.CreateFont(ARIALUNI_TFF, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);

    //Create a specific font object
    iTextSharp.text.Font f = new iTextSharp.text.Font(bf, 12, iTextSharp.text.Font.NORMAL);

    //Write some text, the last character is 0x0278 - LATIN SMALL LETTER PHI
    Doc.Add(new Phrase("This is a ميسو ɸ", f));

    //Write some more text, the last character is 0x0682 - ARABIC LETTER HAH WITH TWO DOTS VERTICAL ABOVE
    Doc.Add(new Phrase("Hello\u0682", f));

    //Close the PDF
    Doc.Close();
}

解决方案

Right-to-left writing and Arabic ligatures are only supported in ColumnText and PdfPTable!

Take a look at the following examples:

Read the book from which these examples are taken to find out why not all words are rendered correctly in peace.pdf

Search http://tinyurl.com/itextsharpIIA2C11 for the corresponding C# version of these examples.

In any case, you need a font that knows how to display Arabic glyphs:

BaseFont bf = BaseFont.CreateFont(ARIALUNI_TFF, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
Font f = new Font(bf, 12);

You can now add Arabic text, for instance in a table:

PdfPCell cell = new PdfPCell();
cell.AddElement(new Phrase("Hello\u0682", f));
cell.RunDirection = PdfWriter.RUN_DIRECTION_RTL;

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

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