gpt4 book ai didi

c# - itextsharp 中的阿拉伯语编码

转载 作者:行者123 更新时间:2023-11-30 16:19:33 25 4
gpt4 key购买 nike

当我尝试使用此代码使用 C# 创建阿拉伯语 PDF 时,生成的 PDF 文件包含离散字符。有什么帮助让我无法获得连续的字符吗?

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

最佳答案

ColumnTextPdfPTable 支持从右到左书写和阿拉伯连字!

看看下面的例子:

阅读引用这些示例的书,找出为什么并非所有单词都在 peace.pdf 中正确呈现

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

无论如何,您需要一种知道如何显示阿拉伯字形的字体:

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

您现在可以添加阿拉伯文本,例如在表格中:

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

关于c# - itextsharp 中的阿拉伯语编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15197040/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com