#9
|
||||
|
||||
![]() Quote:
Code:
var salutation = ReplaceSubstring( Field("Salutation"), // Field("Salutation") will return "Dear Lance" "Lance", // This is the value to be replaced "The Lance-meister" // This is the new value ); // This line will update the value returned by the "Field" function // for the "Salutation" field. FusionPro.Composition.AddVariable("Salutation", salutation); // On second thought, "The Lance-meister" sounds a little too 1985. // Let's update that to "The Lance-inator" FusionPro.Composition.AddVariable("Salutation", ReplaceSubstring( Field("Salutation"), // Field("Salutation") returns "Dear The Lance-meister" "-meister", // This is the value to be replaced "-inator" // This is the new value )); // "Dear?" That's no way to address The Lance-inator. Let's fix that. FusionPro.Composition.AddVariable("Salutation", ReplaceSubstring( Field("Salutation"), // Field("Salutation") returns "Dear The Lance-inator" "Dear", // This is the value to be replaced "Sup" // This is the new value )); Code:
var charMap = { // Find : Replace "Lance" : "The Lance-meister", "-meister" : "-inator", "Dear" : "Sup", } for (var field in FusionPro.Fields) { for (var find in charMap) { var replace = charMap[find]; FusionPro.Composition.AddVariable(field, ReplaceSubstring(Field(field), find, replace), true); } } Code:
// An object of values to find as the keys, // and the string to replace them with as the value. var charMap = { // Find : Replace "’":"’", "’":"'", "¼":"¼", "½":"½", "¾":"¾", "—":"–", "—":"—", } // Loop through all of the fields. for (var field in FusionPro.Fields) { var fieldVal = Field(field); // Loop through all of the find/replace values for current field. for (var find in charMap) { var replace = charMap[find]; fieldVal = ReplaceSubstring(fieldVal, find, replace); } // Update the field's value FusionPro.Composition.AddVariable(field, fieldVal, true); }
__________________
Ste Pennell FusionPro VDP Creator 9.3.15 Adobe Acrobat X 10.1.1 Mac OS X 10.12 |
Thread Tools | Search this Thread |
Display Modes | |
|
|