How do I add an "ñ" character using the .net SDF API?

Q:

I’m trying to add “España” as the location of a digital signature dictionary (following https://www.pdftron.com/pdfnet/samplecode.html#Sig). But when I just add in the string like sigDict.PutString(“Location”, “España”), the location appears garbled when I open the document in another PDF viewer. How can I fix this?

A:

This variant of the PutString API (https://www.pdftron.com/pdfnet/docs/PDFNet/html/M_pdftron_SDF_Obj_PutString_1.htm) performs an implicit encoding conversion. To avoid the conversion, pass in a byte array instead (https://www.pdftron.com/pdfnet/docs/PDFNet/html/M_pdftron_SDF_Obj_PutString.htm); e.g., by calling sigDict.PutString(“Location”, Encoding.Default.GetBytes(“España”)). Doing so should create the characters correctly.

Note also — if you want to store a string using Unicode (i.e. PDF Text Encoding according to PDF spec) you could try
sigDict.PutText(“Location”, “España”);