Search This Blog

Thursday, 27 March 2014

Using the util.print methods

Generally we can you display patterns to for formatting but there are times when we have to format values in code, and there are three handy methods in the Adobe Reader API;

util.printd() for dates
util.printf() for numbers
util.printx() for text

Here are some samples of using these methods;

Code Output Description
var v = util.printx(">?<*","ADOBE")
console.println(v)
Adobe This changes the first character (represented by the ?) to uppercase (represented by the >) and all trailing characters (represented by the *) to lowercase (represented by the <)
var v = util.printx("9999999999","My phone number is (02) 1111 2222")
console.println(v)
0211112222 Copies the first 10 digits, skipping any others characters
var v = util.printd("mmmm",new Date())console.println(v)

March Prints the current month in full.
var v = util.printd("dddd",new Date())console.println(v) Thursday Prints the current day of the week in full
var v = util.printd("date.short(){}",new Date(),true);
console.println(v)
27/03/14 Prints the date in the same format as the "datetime.short{}" display pattern.  The actual output will vary depending on the current locale.
var v = util.printd("date(fr){MMMM}",new Date(),true)console.println(v) mars Prints the current month in French
var v = util.printf("%,105d", 2)console.println(v) 00002 Prints the number 2 in a width of 5 characters with "0" characters padding


No comments:

Post a Comment