Copy link to clipboard
Copied
Hello. Been working in adobe apps for years, but fillable forms are fairly new to me. I am creating a set of forms that have variable-sized fillable text boxes on each page. For instance, one page may require a short statement (ie, went to the park), while the next page would require a long description of that first answer (ie, paragraphs describing how they went to the park and what they did while they were there). Each text box must have a predetermined number of characters since the forms will be printed after they are completed. I have searched but cannot figure out how to (1) let the user know how many characters are allowed in the text box before they start typing and (2) perhaps offer a little note that lets them know how many characters they have left in the text box as they are typing.
Can anyone point me in the right direction to learn more about how to do this? I just can't seem to find the answers.
Thanks,
GS
Copy link to clipboard
Copied
Is the number of allowed characters small, up to 10, say? If so, I would use the Comb option, as it both limits the number of characters allowed in the field, and provides a visual representation of the place for each one, like this:
If it's a larger number then the Comb option will not look very well. In that case you would need to use a script to do both tasks, and put the information in another text field, located next to the one the user edits.
Copy link to clipboard
Copied
Thanks for the reply. All of the answers will be variable, so I don't think the comb will work. One text box might hold 20 characters while the other is the entire page. I'm just not sure how to determine the number of characters that would fit in the box (there must be some easy method other than literally typing characters and counting them). And I'd like to have the little note that says "50 of 100 characters used..." so they will know how many characters they have left so they don't get to the end and have to go back and edit their text.
Copy link to clipboard
Copied
> there must be some easy method other than literally typing characters and counting them
There isn't really. And even doing it like that is tricky, because the width of each character is different, so you have to take that into consideration.
As for displaying the value in another field, you can do it using this code (as the custom Keystroke script of the first field, assuming the second one is named "Text2"):
this.getField("Text2").value = AFMergeChange(event).length + "/" + event.target.charLimit;
After you apply the code it will probably "disappear" and the Format setting will return to None, but it should still work. This is an annoying bug of Acrobat. If you want you can place the code in a doc-level function, so it can be used from multiple fields. You will then need to provide the name of the second field as a parameter, or use a consistent naming scheme to access it without specifying the actual name.
Copy link to clipboard
Copied
It's hard to believe, with the incredible tasks adobe apps can complete, that there isn't an easy way to do this. You'd think almost every form would need this. Oh, well, thank you for the info. This will be on my list of things to dive into.
Thank you!
GS
Copy link to clipboard
Copied
This is not as simple as it might sound. Calculating the length of a string is very complex, and depends on the font used, the text size, the characters used in the string, etc.
Copy link to clipboard
Copied
Most SDKs that handle text and fonts provide a function for calculating text size.
It's a shame Adobe didn't do that for the JS SDK (because the functionality already exists in Acrobat), but there is an indirect technque for determining text length.
The "line" annotation has the ability to display rich text on the line, to support measurments. Create a line annot that is much shorter than the text, then add rich text to it. The line annot takes on the length of the text, plus some extra space. Now you have a good estimate for the text length. TaDa!!
Copy link to clipboard
Copied
This is, it seems to me, going to be variable. Almost all fonts use a mixture of different widths. So a full box could be "siiiiiiiiiix" or "mmmmm". There are no features to tell you how much space is used by the current characters in the selected box, nor whether another character would fit.
Copy link to clipboard
Copied
The OP should obviously use a fixed-width font for this field, as Courier.