我试图用c#将一些unicode字符(阿拉伯语)插入到PDF表单中,我使用了iTextSharp库,但是当我插入字符并在PDF文件中保存字符时,在双击应该出现的切划机位置之前,unicode字符不会显示。
string pdfTemplate = @"c:\po.pdf";
string newFile = @"g:\test\completed_fw4.pdf";
PdfReader pdfReader = new PdfReader(pdfTemplate);
PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileStream(newFile, FileMode.Create));
AcroFields pdfFormFields = pdfStamper.AcroFields;
pdfFormFields.SetField("position", TextBox1.Text);
pdfStamper.FormFlattening = false;
// close the pdf
pdfStamper.Close(); 发布于 2013-08-26 13:27:23
有几种方法可以解决这个问题,但最终您需要指定能够呈现Unicode内容的字体。
首先,创建指向Unicode字体的BaseFont对象,下面使用Arial:
var arialFontPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "ARIALUNI.TTF");
var arialBaseFont = BaseFont.CreateFont(arialFontPath, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);然后,可以在每个字段上分别设置字体属性:
pdfFormFields.SetFieldProperty("position", "textfont", arialBaseFont, null);或者您可以添加一个文档范围的替换字体:
pdfFormFields.AddSubstitutionFont(arialBaseFont);https://stackoverflow.com/questions/18433532
复制相似问题