Library of JavaScript Rules For FusionPro
Library of JavaScript Rules For FusionPro
Library of JavaScript Rules For FusionPro
If you are a user of the FusionPro VDP Creator variable-data-printing software, you probably know it is
possible to instruct FusionPro to manipulate data and make decisions on the fly while it is composing
your output file. You do this from within Adobe Acrobat by clicking FusionPro > Edit Rules... >
New and then either using one of the FusionPro wizards or writing JavaScript code.
This page contains a few useful FusionPro rules written in JavaScript code. Feel free to use them in
your FusionPro projects.
To use any of the rules on this page, follow the procedure shown below. (Of course, you must install
FusionPro VDP Creator if it isn't already installed on your computer. To request a free trial version of
FusionPro VDP Creator, call us at 888-260-7316.)
Launch Adobe Acrobat and open the main PDF file for a FusionPro project
Copy the JavaScript code for the rule that you're interested in, and paste it into the
"Expressions" area
Click the "Validate" button to be sure you haven't made any mistakes
Let's say that your database (or, to use FusionPro terminology, your "instance data") contains name-
and-address information in upper-case letters. What if you want to use that information within your
document, but you don't want it to be in upper-case letters?
This handy rule converts upper-case data to mixed-case data (first letter is upper-case; other letters
are lower-case).
var theFNameUpper = Field("FIRST_NAME");
var theLowerLength = theFNameUpper.length - 1;
return Left(theFNameUpper, 1) + Right(theFNameUpper,
theLowerLength).toLowerCase();
When using this rule, replace FIRST_NAME with the name of the database field that
you're dealing with.
This rule lets you print 212 Main St., Apt 44 if your database record contains an apartment number but 212 Main
St. if your database record doesn't contain an apartment number. Notice that the comma is printed if there is an
apartment number, but the comma is not printed if there is no apartment number.
It happens all the time — you have a database that contains a field called ADDRESS1 (or something
like that) for the street name and another field called ADDRESS2(or something like that) for the
apartment number or suite number. Typically, some of the records in the database have an apartment
number or suite number and some do not.
Now, you might want to print the ADDRESS2 data on the same line with the ADDRESS1 data, with a
comma between them — but you certainly don't want the comma to show up if there is no ADDRESS2
data.
How can you accomplish this? The handy rule below will take care of it for you.
function StrIsEmpty(Str)
{
var idx = 0;
var nonSpaceCharCtr =0;
while(idx < Str.length)
{
if(Str.charAt(idx) != ' ') {nonSpaceCharCtr++;}
idx++;
}
return( ! nonSpaceCharCtr > 0);
}
if( ! StrIsEmpty(Field("ADDRESS2")) )
return(", " + theData);
else
return("");
When using this rule, replace ADDRESS2 with the name of field in your database that
contains the apartment number or suite number.
You've run your database through postal-automation software to look up the nine-digit Zip codes, to
look up the Delivery Point Codes, to append the "check digit" or "parity digit," and to sort the records
into the required order. Now, your database contains a field with the twelve digits that are to be used
for the POSTNET bar code — but you're still not ready to use the database, because the bar-code font
that you're using will not create the frame bars (the tall bars at the beginning and end of the POSTNET
bar code) unless you put a special character before and after the twelve digits.
So what do you do? Do you open your database in a text editor and type that special character before
and after each twelve-digit sequence of numbers, hoping that you are careful enough not to make any
mistakes?
NO!! At least, not unless you have lots of time, and not unless you want to risk introducing errors into
your freshly processed database!