Copy link to clipboard
Copied
Hello,
I am looking for help writing the code for a PDF DC form. I want all the vowels in a string of entered data to appear red; while the other letters remain the same as preset. How do I do this? Thank in advance for your help!
c
Copy link to clipboard
Copied
I like a good challenge, so I wrote it for you... Use this code as the field's custom validation script. Just make sure to tick the "Rich Text Formatting" box under the Options tab of the field's Properties.
The code:
var newValue = event.value;
var letters = newValue.split("");
var newRichValue = [];
for (var i in letters) {
var span = {};
span.text = letters;
span.textColor = isVowel(letters) ? color.red : color.black;
newRichValue.push(span);
}
event.richValue = newRichValue;
function isVowel(s) {
return /^[aeiou]$/i.test(s);
}
Copy link to clipboard
Copied
That is quite tricky. You would need to use Rich Text Formatting and parse the value the user inputs, splitting it into single letter spans and applying the desired font style to each span, and then merge them into a single spans array and apply it back to the field's richValue property.
Copy link to clipboard
Copied
I like a good challenge, so I wrote it for you... Use this code as the field's custom validation script. Just make sure to tick the "Rich Text Formatting" box under the Options tab of the field's Properties.
The code:
var newValue = event.value;
var letters = newValue.split("");
var newRichValue = [];
for (var i in letters) {
var span = {};
span.text = letters;
span.textColor = isVowel(letters) ? color.red : color.black;
newRichValue.push(span);
}
event.richValue = newRichValue;
function isVowel(s) {
return /^[aeiou]$/i.test(s);
}
Copy link to clipboard
Copied
oh my gosh it works you are my hero!!!!!
One more questions... What if I wanted the consonants to be blue and not
black?
Copy link to clipboard
Copied
In line #7 in the code above change color.black to color.blue...
Copy link to clipboard
Copied
❤
Thank you !!!!
Copy link to clipboard
Copied
Thank you.
I have improved the script so that it can be used in French:
var newValue = event.value;
var letters = newValue.split("");
var newRichValue = [];
for (var i in letters) {
var span = {};
span.text = letters;
span.textColor = isVowel(letters) ? color.red : color.blue;
newRichValue.push(span);
}
event.richValue = newRichValue;
function isVowel(s) {
return /^[aàäâeéèëêiïîoôuûùyÿ]$/i.test(s);
}
Acrobate du PDF, InDesigner et Photoshopographe

