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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With