Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi,

I have asked a similar question in the past but I have solved it. This question is regarding the (Let's call it) "Miscommunication" between C# and PDF(ITextSharp). I am hoping someone can assist me in this.

The scenario is that in the PDF coded file there is already font included and to my understanding the font does cater for the special characters. IE é,ê,ò,ô etc. Now the problem comes in when i debug the code.

You see I can see in the process that all the characters etc are passed successfully into the pdf

C#
PdfReader pdfReader = new PdfReader(pdfTemplate);
pdfStamper = new PdfStamper(pdfReader, new FileStream(newFile, FileMode.Create));
AcroFields pdfFormFields = pdfStamper.AcroFields;

pdfFormFields.SetField("PYN", person.PersonFullname);


person.PersonFullname is "TRÉVOR MÏCHAËL SCHWAÎTZ". This passes exactly like this to the pdf through the code. But once the file is created and i can only see in the pdf this: "TRVOR MCHAL SCHWATZ".

In the PDF coded version i can see that the font is included. Now what I can see the problem comes in at the name in setfield.

because this works fine (Note it is in the same pdf. I just cannot figure out if the font might be the problem in specific cell.)

C#
pdfFormFields.SetField("BDFC", person.PersonFullname);


Like I said the above prints correctly TRÉVOR MÏCHAËL SCHWAÎTZ.

Anyone have any idee what to look for or what the problem might be?
Posted

1 solution

I solved it myself!

But for those that may stumble upon this question I will post the answer for you.

Seems the coder before me change the font for the specific field and that field does not support special characters.

C#
BaseFont fieldFontRoman = 
BaseFont.CreateFont(@"C:\Windows\Fonts\timesnr.ttf", 
                                    BaseFont.IDENTITY_H, 
                                    BaseFont.EMBEDDED); 

            pdfStamper.AcroFields.SetFieldProperty("PYN", "textfont", 
fieldFontRoman, null);


So i just removed the SetFieldProperty that uses the specific font (for some reason)

So in short you can use a specific font that you do know has it. The other thing is in the PDF Coded creator you must also ensure under properties that all the included/embedded fonts can handle any needed special characters that you might need in the future etc.

Hopes my solution will be of help for any future questions that is the same :-)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900