Skip to main content
Inspiring
May 3, 2021
Question

Truncate Text in Adobe Acrobat

  • May 3, 2021
  • 1 reply
  • 1910 views

Hi there

 

Trying to create a form to where in one cell, they place the person's name - Chandler, Michael Stevens

 

Then another cell references that cell, and I want it to just have Chandler and anything after the , is truncated. I tried to search online for this but the formula I found does not work 100%. Any help would be greatly appreciated. 

This topic has been closed for replies.

1 reply

JR Boulay
Community Expert
Community Expert
May 3, 2021

You can use this script as a Validation script in the field where they place the person's name:

 

aTexte = event.value;  // get the value
aTexte = aTexte.split(" ");  // use the blank space to split the value into array
aTexte = aTexte.shift();  // get the first element of the array
aTexte = aTexte.replace(",", "");  // remove the comma if exist
this.getField("targetTextFieldName").value = aTexte;  // assign the resulting value to the target field

Acrobate du PDF, InDesigner et Photoshopographe
Inspiring
May 3, 2021

You are awesome! Thank you. Side question.... 
So, another thing I am wanting to see if is possible...

Have a drop down of various salutations:
 Dear Mr. & Mrs..
 Dear Mr. 

 Dear Mrs. & Mrs. 

 

Etc. But, depending on the drop down, have the field that pulls just the last name, to where it reads:

     Dear Mr. & Mrs. Chandler
This will allow for the text to all flow as a normal letter and not a huge gap. Thank you!!

try67
Community Expert
Community Expert
May 3, 2021

Instead of the above use this code as the custom calculation script of the text field (adjust the field names as needed in the code):

 

 

var fullName = this.getField("FullName").valueAsString;
var prefix = this.getField("Prefix").valueAsString;
if (fullName!="") {
	var surname = fullName.split(",")[0];
	event.value = prefix + " " + surname;
} else event.value = "";

 

Edit: Code fixed