Wednesday, 29 August 2018

Count the Number of Words

How to Count/limit number of words entered by a user?

If you want to go beyond the basic restrictions or want to apply some more logical boundations then Regular Expression would be the right solution.

Below is the example to restrict the user to not enter more than 5 words.

Limit Words


if (xfa.event.newText.match(/\b\w+?\b/g).length > 5)

          xfa.event.change = "";
          app.alert("Maximum of 5 words are allowed");


Show login name of the user

How to get the Username/ Login Name of the user who filled the form?

Due to security reason in PDF, this task becomes quite difficult to achieve and is only feasible for the intranet environment.
Firstly, you need to create a Trusted Function at the folder level script which checks the login name and returns the value to a form field. Here the hierarchy of the LC form is important. The result will map to the specific field in the form.

Place the following script in the Javascript folder of Acrobat or Reader depending on your requirement:
For Example:
C:\Program Files (x86)\Adobe\Acrobat DC\Acrobat\Javascripts
C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\Javascripts

var TrustMe = app.trustedFunction(function(doc){app.beginPriv(); var IdentField = this.xfa.form.Form1.Page1.LoginUserName;IdentField.rawValue = this.identity.loginName;  app.endPriv(); });

Now, the main part is done and you just need to call the function which is placed at the folder level JavaScript.  

Put this script in the form:ready event of the form or any button to call the function;

Show Login Name

Download the files from the following link and place the .js file at the JavaScripts folder mentioned above and then open the PDF and click "Get" button.


Cursor focus on specific field

To move the focus on the specific field.

Many a times, we need the cursor to move to specific field based on our requirement. The most common scenarios are - validation of fields and Tab Order.

Use the following script to focus.


if (event.fieldFull) {

Radio Button as mandatory field

How to make the radio button group as required.

By default, LC Designer doesn't validate the NULL value of the Radio Button Group as Required Field. We need to use JavaScript to implement the logic.
In my example I used a button to first validate the Radio Button Group and if it is not NULL then it sends an email.

Radio Button Required

if(RadioButtonList.yes.rawValue == null && == null)
app.alert("Please select the option");

var eid = "";
var sub = "test subject";
var bdy = "Sample Body";{cURL:"mailto:" + eid + "?subject=" + sub + "&body=" + bdy ,cSubmitAs:"PDF",cCharset:"utf-8"});


Convert Numbers into Words

WordNum is the function which returns the English text equivalent of a given number.

For Example:
WordNum(123.45)One Hundred and Twenty-three Dollars
WordNum(123.45, 1)One Hundred and Twenty-three Dollars
WordNum(1154.67, 2)One Thousand One Hundred Fifty-four Dollars And Sixty-seven Cents
WordNum(43, 2)Forty-three Dollars And Zero Cents
WordNum(Amount[0], 2)
This example uses the first occurrence of Amount as the conversion number.
 However, there is a limitation in this fuction. It only converts the two decimal values and if you want to English conversion for more than 2 decimals then you need to use the JavaScript to modify the function.
This is required in case of currency conversion for example Omani Rial, where 3 decimal values are acceptable.

Note: This function runs in Formcalc language so all coding needs to be done in FormCalc only.

Number To Word

if ($.rawValue == "OMR") then
var last = right(TextField1,3)
var part1 = Concat(WordNum(TextField1), " rials And ")
var part2 = Concat(WordNum(last) , " baisa")
TextField2.rawValue = Concat(part1 , part2)