Creating a PDF form field with Rich text.

Q: I got stucked in trying to use annotation RV dictionary in both
fields and free text (RC). I tried everything, from using sample rich
text string from PDF reference manual to extracting RV entry from fdf
(using acrobat) and pasting it in dictionary. DS dictionary worked as
long a used only one settings value (i.e font: 10 Arial), but if I
added more styles using semicolon delimeter no styles were applied. My
code snipet is pasted below, please let me know if you think there is
a bug, or I am doing something wrong. Thx!

pdftron.PDF.Annots.Widget annot = pdftron.PDF.Annots.Widget.Create
(pageinfo.doc.GetSDFDoc(), rect, pageinfo.doc.GetField(name));
annot.SetFlag(Annot.Flag.e_print, true);

pageinfo.doc.GetField(name).SetFlag(Field.Flag.e_rich_text, true);

pageinfo.doc.GetField(name).GetSDFObj().PutString(\"DS\", \"text-
align: justify\");
pageinfo.doc.GetField(name).GetSDFObj().PutString(\"RV\", \"(<?xml
version=\\\"1.0\\\"?><body xfa:APIVersion=\\\"Acroform:\\\"
xfa:spec=\\\"2.1\\\" xmlns=\\\"\\\"
xmlns:xfa=\\\"\\\"><p dir=\\
\"ltr\\\" style=\\\"margin-top:0pt;margin-bottom:0pt;text-
\">this is some text</p></body>)\");

A: I assume that you are creating or filling a PDF form with Rich text
and would like to display it Acrobat or some other PDF Reader. For
Rich text fields you should not use RefreshAppearances() in Field or
PDFDoc because PDFNet appearance generator at the moment ignores RC
entry. Instead you should set the "NeedAppearances" flag in AcroForm
dictionary as follows:

doc.GetAcroForm().PutBool("NeedAppearances", true);

This will force the viewer application to auto-generate new appearance
streams for your form fields.

In case the problem is still there, there may be something wrong with
your DS or RV string. You may want to use CosEdit utility (http:// to inspect your PDF and compare
it with contents of a PDF document that displays properly.

please disregard my previous emails, I found the problem on the end.
PDF reference prescribes algorithm which ensures that old viewer can
support rich text string by comparing values at V and RV entries in
dictionary. So, if field value is not equal, DS entry kicks in to
formulate new string using flat string from V.

Learned a lot from this, but it was painful. So, no bug in Pdftron! :slight_smile: