Copy link to clipboard
Copied
Hello community,
I created a button on Adobe PDF, so when the user click on it, it creates 3 fields per row(Amount of times it is clicked the button).
I set up the font size and the font using:
newField.textFont = "Helvetica";
newField.textSize = 9;
And newField is: var newField = this.addField(...)
Now, I want to know the code to give the instructions that newField should be "Numeric" Format and with 3 decimals: 5.000 (Example)
Thanks
Copy link to clipboard
Copied
Change this block:
var customFormat = AFNumber_Format(3, 0, 0, 0, "", false);
var myField = this.getField(fieldName );
myField.setFormat(customFormat);
To:
var customFormat = "AFNumber_Format(3, 0, 0, 0, \"\", false)";
var myField = this.getField(fieldName);
myField.setAction("Format", customFormat);
Copy link to clipboard
Copied
There isn't a direct command to do it. You would need to use the setAction method to specify the Format and Keystroke scripts for the field, and either write your own code that does it, or have knowledge of the undocumented functions that Acrobat uses to apply those settings.
Copy link to clipboard
Copied
Thanks for the response, do you have any website or link where I can find those undocumented functions (I know is undocumented) but maybe somewhere there is this info please.
Copy link to clipboard
Copied
You're asking about the AFNumber_Format function. If you execute the function name in the Acrobat JavaScript console window you'll see the whole thing.
https://www.pdfscripting.com/public/images/video/AcroJSIntro/AcroJSIntro_ConsoleWindow.cfm
You would be better served to just set the format using the "util.printf()" function.
https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/JS_API_AcroJS.html#printf
Copy link to clipboard
Copied
Thanks to you guys, I tried my best, but I did not make it function 😞
My Javascript code is in a button, each time the user clicks on it, it adds a new row of fields, but the fields that are manually setted up as Numeric with 3 decimals since row number two(2) it is not functioning, it is without any format.
This is my JS code in the button:
var totalCount = 1;
var totalCount2 = 0;
for (var fieldNumber = 0; fieldNumber < numFields; fieldNumber ++)
{
if(getNthFieldName(fieldNumber).startsWith("CONTAINER_CONTAINER_NRO")){
totalCount++;
totalCount2++;
}
}
var offset = this.getOffset();
var fieldNames = this.getFieldNames();
for (var i = 0; i < fieldNames.length; i++)
{
var fieldName = fieldNames[i] + "_";
var rectLast = this.getField("CONTAINER_" + fieldName +totalCount2 ).rect;
var newField = this.addField("CONTAINER_" + fieldName + totalCount, "text", 1, [rectLast[0],rectLast[1] - offset ,rectLast[2],rectLast[3]-offset ]);
if(fieldName === "QUANTITY_VOL_"){
var customFormat = AFNumber_Format(3, 0, 0, 0, "", false);
var myField = this.getField(fieldName );
myField.setFormat(customFormat);
}
}
this.getField("REMOVE_CONTAINER").display = display.visible;
if(totalCount >= this.getMaxQuantityFields()){
this.getField("ADD_CONTAINER").readonly = true;
}
Inside the body of the 'if' it is where I want place my code that will give a Numeric Format and set up to 3 decimals to whichever value the user input into the field, the name of the field is: "QUANTITY_VOL_")
I do not have idea what I am doing wrong.
Copy link to clipboard
Copied
Change this block:
var customFormat = AFNumber_Format(3, 0, 0, 0, "", false);
var myField = this.getField(fieldName );
myField.setFormat(customFormat);
To:
var customFormat = "AFNumber_Format(3, 0, 0, 0, \"\", false)";
var myField = this.getField(fieldName);
myField.setAction("Format", customFormat);
Copy link to clipboard
Copied
Thanks to you all guys, this last help solved my problem.
I found documentation about this, it is in the following link, it is a PDF the information related to set a format and decimals is on page 68:
Acro6JSGuide.pdf(Review) - Adobe cloud storage