I use iTextSharp version 5.4.1.0, if that matters.
-----Original Message----- From: Kostas [mailto:k...@dataverse.gr] Sent: Monday, January 13, 2014 12:05 PM To: 'Post all your questions about iText here' Subject: [iText-questions] PDF fields not rendering correctly on Acrobat Reader Hello. I have a PDF file with digital signatures and some comment fields which I lock after a signature is added. I have the following problem: When I insert a comment, that has Greek and English words in it, into a field with iTextSharp, Acrobat Reader XI has problem displaying both English and Greek (usually it hides the English words). However, Acrobat Pro 8 displays it fine! (I have also tried to check the Acrobat settings for Page Display", but didn't find anything different...) I attach the file (just in case someone wants to have a look at it). The comment at the end of the document says : "Δοκιμή 123 γάτα ms-dos σχολίου. Test abc εποχή. Απόφαση test γάτα κότα σκύλος abc ρήτορ. ΄δσα;φ" ...but Acr. Reader shows "Δοκιμή 123 γάτα σχολίου. εποχή. Απόφαση γάτα κότα σκύλος ρήτορ. δσαφ " I have tried various things revolving around fonts and their subsets, but I had no luck. This is how I create the comment fields: ---------------------------------------------------- BaseFont bf = GetBaseFont(true); CreateTextFieldCell(writer, FieldNameComment + id, bf, BaseColor.WHITE) protected BaseFont GetBaseFont() { BaseFont bf; bf = BaseFont.CreateFont(UnicodeFont, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); bf.Subset = false; // This will force the embedding of the whole font file. bf.CompressionLevel = 9; //the compression level (0 = best speed, 9 = best compression, -1 is default) return bf; } public static string UnicodeFont { get { string pathToUniFont = System.Configuration.ConfigurationManager.AppSettings["UnicodeFontFilePath"] ; // Get Times New Roman. if (!File.Exists(pathToUniFont)) throw new Exception("Configuration variable 'UnicodeFontFilePath' not found!"); return pathToUniFont; } } private PdfPCell CreateTextFieldCell(PdfWriter writer, String name, BaseFont bf, BaseColor background = null) { var cell = new PdfPCell {MinimumHeight = 50}; var field = new TextField(writer, new Rectangle(0, 0, 0, 0), name) { MaxCharacterLength = 2000, Font = bf, FontSize = 0, // This should AutoSize the font... Alignment = Element.ALIGN_LEFT, Options = PdfFormField.FF_MULTILINE | PdfFormField.FF_DONOTSCROLL, BackgroundColor = background ?? new BaseColor(200, 200, 250), //BorderColor = BaseColor.BLACK, BorderWidth = 0.0f, ExtensionFont = GetSubstitutionFont(true), BorderStyle = PdfBorderDictionary.STYLE_INSET, FieldName = name }; cell.CellEvent = new PDFSignatureFieldEvent(field.GetTextField()); cell.BorderColor = BaseColor.BLACK; cell.BorderWidth = 1.0f; cell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER | Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER; return cell; } protected BaseFont GetSubstitutionFont(bool embedded = false) { BaseFont bf; if (embedded) { bf = BaseFont.CreateFont(UnicodeSubstitutionFont, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); } else { bf = BaseFont.CreateFont(UnicodeSubstitutionFont, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); } bf.Subset = true; return bf; } And this is how I fill them: ------------------------------------ var pdfStamper = new PdfStamper(pdfReader, memStrm, '\0', true); // We're using PdfStamper in append mode to avoid breaking the signatures. SOS! var aFields = pdfStamper.AcroFields; var fieldsDic = aFields.Fields; if (fieldsDic.Count > 0) { // Comment. string fieldLabel = "fieldName1"; AcroFields.Item fIt = fieldsDic.FirstOrDefault(field => field.Key == fieldLabel && field.Value != null).Value; aFields.SetFieldProperty(fieldLabel, "setfflags", PdfFormField.FF_READ_ONLY, null); // Make it readonly. //aFields.SetFieldProperty(fieldLabel, "textfont", GetBaseFont(true), null); bool ret = aFields.SetField(fieldLabel, comment, comment); // Add comment. } If someone sees anything wrong, please let me know. My best guess was BaseFont.setSubset(false), but inserting it in my GetBaseFont() didn't help much. :( I use "Time New Romans" as a main font for my fields and "Arial Unicode" as an ExtensionFont (from the GetSubstitutionFont()). Thanks, and sorry for bugging you. ------------------------------------------------------------------------------ CenturyLink Cloud: The Leader in Enterprise Cloud Services. Learn Why More Businesses Are Choosing CenturyLink Cloud For Critical Workloads, Development Environments & Everything In Between. Get a Quote or Start a Free Trial Today. http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk _______________________________________________ iText-questions mailing list iText-questions@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/itext-questions iText(R) is a registered trademark of 1T3XT BVBA. Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/ Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php