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.)
PROCEDURE FOR USING THE RULES SHOWN ON THIS PAGE
- Launch Adobe Acrobat and open the main PDF file for a FusionPro project
- Click FusionPro at the top of the Adobe Acrobat window.
- Click Edit Rules... > New > Empty Rule
- Click the "Next" button
- Type a name for your rule in the "Rule Name" box
- Copy the JavaScript code for the rule that you're interested in, and
paste it into the "Expressions" area
- Modify it as needed to fit your situation
- Click the "Validate" button to be sure you haven't made any mistakes
- Click the "OK" button
- Click the "OK" button
- Utilize the rule in a text frame
- Use FusionPro VDP Creator to compose the document
- Observe the results
Rule for converting upper-case data to mixed-case data
|
This rule lets you convert VICKI to Vicki, CHARLES to Charles, etc.
|
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.
Rule for printing optional address field with comma
|
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);
}
var theData = Field("ADDRESS2");
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.
Rule for adding frame-bar characters to POSTNET data
This rule lets you convert 230279724446 to s230279724446s
or 230279724446 to /230279724446/
or 230279724446 to |230279724446|,
etc.
|
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!
What you should do is use the simple rule below.
var theData = Field("POSTNET_DATA");
return "s" + theData + "s";
When using this rule, replace POSTNET_DATA with the name of the
database field that contains the twelve digits for the POSTNET bar code,
and replace each s with the special character that is
required by the POSTNET bar-code font that you're using. (Here,
we've used the s because that's what is required by the
"AdvPNETn" bar code. AdvPNETn is one of the bar-code
fonts that comes with the FusionPro software, and we've used it
for several of our FusionPro projects. Other bar-code fonts
might require a different character for this purpose. For example,
some fonts require the / character, and some require
the | character.)
|