问题描述
当我试图此代码创建一个使用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正确呈现的书
搜索的对这些例子相应的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:
- http://itextpdf.com/examples/iia.php?id=205 with result: say_peace.pdf
- http://itextpdf.com/examples/iia.php?id=215 with result: peace.pdf
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编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!