填补Unicode字符PDF格式 [英] fill pdf form with unicode characters

查看:125
本文介绍了填补Unicode字符PDF格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图插入一些Unicode的字数(阿拉伯语),以PDF形式用C#我用iTextSharp的库,但是当我插入字符和保存字符在PDF文件中的Unicode字符没有得到显示,直到我双击的位置。应该出现chracters

 字符串pdfTemplate = @C:\po.pdf 
串NEWFILE = @G:\test\completed_fw4.pdf
PdfReader pdfReader =新PdfReader(pdfTemplate);
PdfStamper pdfStamper =新PdfStamper(pdfReader,新的F​​ileStream(NEWFILE,FileMode.Create));
AcroFields pdfFormFields = pdfStamper.AcroFields;
pdfFormFields.SetField(位置,TextBox1.Text);
pdfStamper.FormFlattening = FALSE;
//关闭PDF
pdfStamper.Close();


解决方案

有一对夫妇的方法可以解决这个问题,但最终你需要指定一个字体,能够呈现您的Unicode内容。



首先,创建一个 BASEFONT 对象指着你的Unicode字体,我用下面的Unicode Arial字体:

  VAR arialFontPath = Path.Combine(Environment.GetFolderPath(环境.SpecialFolder.Fonts),ARIALUNI.TTF); 
VAR arialBaseFont = BaseFont.CreateFont(arialFontPath,BaseFont.IDENTITY_H,BaseFont.EMBEDDED);



然后就可以设置每个字段的字体属性分别:

  pdfFormFields.SetFieldProperty(位置,TEXTFONT,arialBaseFont,NULL); 



或者你也可以添加大量文档替换字体:

  pdfFormFields.AddSubstitutionFont(arialBaseFont); 


I am trying to insert some unicode charaters (arabic) to PDF form with c# I used iTextSharp library but when I insert the characters and save characters in the PDF file the unicode characters not getting displayed until I double click on the position of the chracters that should be appeared.

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

解决方案

There's a couple of ways that you can fix this but ultimately you need to specify a font that is capable of rendering your Unicode content.

First, create a BaseFont object pointing to your Unicode font, I'm using Arial Unicode below:

var arialFontPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "ARIALUNI.TTF");
var arialBaseFont = BaseFont.CreateFont(arialFontPath, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);

Then you can either set the font property on each field individually:

pdfFormFields.SetFieldProperty("position", "textfont", arialBaseFont, null);

Or you can add a document-wide substitution font:

pdfFormFields.AddSubstitutionFont(arialBaseFont);

这篇关于填补Unicode字符PDF格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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