Skip to main content
Celentano Fabio
New Participant
October 3, 2021
Question

change the format of several fields in one step

  • October 3, 2021
  • 2 replies
  • 2415 views

I have a problem: i generate many pdf-formulars for many companies. I often have to change the format for over 50 fields at the same time. 50 fields will change from standard to integer format. Sometimes i have to change 50 fields from integer format with two decimal places to one decimal place. 

 

How can i do that for several fields at the same time? Currently i change one filed by another. And that is no clean solution!

 

Best regards and thanks for your help

This topic has been closed for replies.

2 replies

Nesa Nurani
Community Expert
Community Expert
March 19, 2024

Edited.

New Participant
March 19, 2024

It's possible to change the format of the fields to currency after it is calculated with out going into the formatting console?

JR Boulay
Community Expert
Community Expert
October 3, 2021

Paste this script in the JS Console, select all, and hit the Enter key:

 

for (var i = 0 ; i < this.numFields ; i++) {
var oFld = this.getField(this.getNthFieldName(i));
if ((oFld.type == "text") && (/total/.test(oFld.name))) {
oFld.setAction("Format","event.value = util.printf(\"%,2.0f\",event.value) ;");
}
}

 

 

It will change the Format of all text fields whose name contains total like this:

 

 

You can assign the format you want by setting printf:

https://opensource.adobe.com/dc-acrobat-sdk-docs/acrobatsdk/html2015/Acro12_MasterBook/JS_API_AcroJS/util_methods.htm?rhhlterm=printf&rhsyns=%20#XREF_95657_printf

Acrobate du PDF, InDesigner et Photoshopographe
Participating Frequently
March 18, 2024

I am trying to use the code above to change multiple text boxes at the same time from integer to 1 decimal point but it doesn't seem to work.  The code I am using is below and all I have changed is for the file name to contain 'TestCPL' and the format from '%,2.0f' to %,2.1f (1 decimal point).

I have then selected all the fields on the page and hit enter but nothing seems to change in the field names that contain TestCPL.  Can you please tell me what I am doing wrong?

try67
Community Expert
Community Expert
March 19, 2024

You don't need to select the fields. You need to select the code in the JS Console and press Ctrl+Enter to execute it.