• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

change the format of several fields in one step

New Here ,
Oct 03, 2021 Oct 03, 2021

Copy link to clipboard

Copied

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

TOPICS
PDF forms

Views

559

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 03, 2021 Oct 03, 2021

Copy link to clipboard

Copied

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:

 

Capture_113.png

 

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...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 18, 2024 Mar 18, 2024

Copy link to clipboard

Copied

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).

Daphne5C23_0-1710781034016.png

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 19, 2024 Mar 19, 2024

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 19, 2024 Mar 19, 2024

Copy link to clipboard

Copied

Thank you for responding. 

 

I now seem to get the message 'undefined' under the code after I execute it

Daphne5C23_0-1710867613309.png

You can see the field names in the screenshot below and there are definitely a number of them in the first two rows that contain 'TestCPL' as part of the name.

Daphne5C23_1-1710867964437.png

 

  

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 19, 2024 Mar 19, 2024

Copy link to clipboard

Copied

"undefined" is not an error, the opposite, actually.

Check if the fields were actually edited.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 20, 2024 Mar 20, 2024

Copy link to clipboard

Copied

They didn't change.  My fields are currently set to zero decimal points and I am trying to set them to 1 decimal point.  After executing that code they still remain at zero decimal points.

Daphne5C23_0-1710925485926.png

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 20, 2024 Mar 20, 2024

Copy link to clipboard

Copied

Daphne5C23 since it's a grid of fields you don't need to use a script.

Remove all fields except the first one, set the Format, then right-clic on the field and use "Create multiple copies".

This should take about 30 seconds.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 20, 2024 Mar 20, 2024

Copy link to clipboard

Copied

LATEST

Thanks for your suggestion.  I do use the 'Create Multiple Copies' function when starting a form from scratch but sadly that is not an option for me on this occassion. 

 

I actually have several existing forms to amend, each one with many fields in a grid pattern.  Almost all of those fields contain individual validation scripts checking target values against actual values and formatting the text colour accordingly so if I used the create multiple copies method I would then have to amend all those validation scripts individually instead so it would actually take several hours.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 20, 2024 Mar 20, 2024

Copy link to clipboard

Copied

That's because the code you got will not set the built-in Number option of the Format tab.

Try this:

 

oFld.setAction("Format", "AFNumber_Format(1, 0, 0, 0, \"\", false)");
oFld.setAction("Keystroke", "AFNumber_Keystroke(1, 0, 0, 0, \"\", false)");

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 20, 2024 Mar 20, 2024

Copy link to clipboard

Copied

That works perfectly!  Thank you so much for all your help. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 19, 2024 Mar 19, 2024

Copy link to clipboard

Copied

Edited.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 19, 2024 Mar 19, 2024

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines