I want to restrict users from changing font and its size even when the rich text is enabled..... or if they have changed it will be reverted back when the file is opened next time.
Is it possible.
Copy link to clipboard
It is. However, if you just want to use a fixed font and size, just set the field to have a fixed font and size... or did you want them to be able to use other types of rich formatting?
I want that user cannot change the font, font size, but they can do underline, strikethrough, bold etc...
is it possible??
You can't prevent them from changing it, but you can use a script to change it back to the desired settings under the Validation event of the field, I believe.
Yes - It's possible but not particularly straight forward and would best be run only after the user has committed the field. You'll need to have a good understanding of how JSON objects work and how to write recursive functions to dig through the formatting in its source format. If you are new to this, you might consider hiring someone to do it. Thought, not me at the moment.
Why does it need to be recursive? The spans object is a straight forward array, as far as I recall.
I believe the recursive bit Joel is referring too to parsing JSON, not specific to the spans object.
Spans doesn't give you access to all of the properties that can be set in the Acrobat UI and depending on how the user does their formatting, the formats can get weird nesting. It's best to edit the JSON content directly without going through the spans Object. The Spans Object is a JSON Object but the definition of it in Acrobat has a limited number of properties to get and set. With the JSON content, you can get and set whatever properties are in the JSON.
Always remember... .toSource() can be a frustrated programmer's best friend.
In the line of try67's comment, you would save the current span Object array (at latest in the onFocus Event), and compare the edited one with it in the Validation Event. Then you can reset the font sizes etc.
A simplification is when the properties you want to control are all the same within the field; then you simply would reset those values in the span Object.