how do I format subscript/superscript characters in a text field?

I am creating a form where the user enters a formula in a linear format and then javascript takes that value and reformats it as variables with superscripted and subscipted characters.


event.rc = true;
if (event.value != "")
event.value.toUpperCase() != "N_X=E_X*N_A/E_A" &&
event.value.toUpperCase() != "N_X=E_XXN_A/E_A"
app.alert ("Incorrect, Try Again...Enter Subscripted Formulas in a Linear Format\r + (ie. E\u2093=I\u2090xR\u2090 would be entered as E_X=I_A*R_A).");
event.rc = false;
event.value = "N\u2093=E\u2093N\u2090/E\u2090";

This works but I need to do this with N_P=E_P*N_S/E_S.

How can I write a subscripted-P and a subscripted-S to the field?

Brett Fleming

2 Answers

Voted Best Answer

First of all, document.write() is not an object and a method that are supported in Acrobat JavaScript, only in browsers.

To have text in a text field show up as sub- or superscript you need to use the Rich Text Formatting option. Enable that in your field and then read about the richValue property and how to set it using an array of Span objects. Among the properties of these objects are subscript and superscript.


Visit my custom-made PDF scripts website:
Contact me personally:

By Gilad D (try67)   

I see what you mean, but how do I take a users input, reformat it and write it back to the field in the correct format. Where can I read about richValue property and how to set it using an array of Span objects?

I am somewhat new to this.

I also am not sure why this routine works if document.write() is not supported. I am using Acrobat pro X.

Brett Fleming   

Please specify a reason: