2013-03-04 133 views
3

當我嘗試使用C#在阿拉伯語中創建PDF時,生成的PDF文件包含離散字符。任何幫助,所以我不能得到連續的字符?itextsharp中的阿拉伯語編碼

//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(); 
} 
+0

我面臨這樣的:

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

現在,您可以在表中添加阿拉伯語的文字,例如問題之前,你可以看看我的問題「轉換阿拉伯語」unicode「內容html或xml到使用itextsharp的pdf」,這可能會幫助你http://stackoverflow.com/questions/16080741/convert-arabicunicode-content-html-或-XML到PDF的使用-iTextSharp的 – 2015-07-27 14:32:40

回答

3

從右到左書寫和阿拉伯語結紮在ColumnTextPdfPTable只支持!

看看下面的例子:

閱讀從中提取這些例子中找出原因的書並非所有單詞都能正確呈現在和平.pdf

搜索http://tinyurl.com/itextsharpIIA2C11爲這些示例的相應C#版本。

在任何情況下,你需要知道如何顯示阿拉伯語字形字體:

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