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

PDF Forms JS: Extract formatted number field as displayed into a string

New Here ,
Nov 10, 2019 Nov 10, 2019

Hello,

 

Everything is in the object.

I've developed a relatively complex pdf form with JS customization.

 

I would like to insert in a text field a string that would contain a formatted number field as it is displayed.

 

Example: the numerical value is 25.1 is displayed in the field as 25,10 USD***, (the formatting changes depending on user's choices in other fields, for example the same value might be displayed as 25,100 TND*** ...) 

I wish to extract the string "25,10 USD***" not the 25.1.

I tried using the formattedValue/editValue/rawValue properties but none of those worked.

 

Is it possible to do what I want? If so, how can I do it?

 

Thanks

TOPICS
PDF forms
2.8K
Translate
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
1 ACCEPTED SOLUTION
Community Expert ,
Nov 11, 2019 Nov 11, 2019

Formatting in Acrobat forms is done with JavaScript.

Try the "util.printx()"function.

https://help.adobe.com/en_US/acrobat/acrobat_dc_sdk/2015/HTMLHelp/#t=Acro12_MasterBook%2FJS_API_Acro...

 

But the better function is "util.printf()"

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

View solution in original post

Translate
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 ,
Nov 10, 2019 Nov 10, 2019

You must format the value.

Translate
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 ,
Nov 10, 2019 Nov 10, 2019

Hello,

 

How can I achieve it?

I was able to format the number field (separator style, decimals, currency suffixe...) and display it correctly, but can't get the result in a string so I can use it in another text field.

 

Thanks

Translate
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 ,
Nov 10, 2019 Nov 10, 2019

You can use util.printf for this.

Translate
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 ,
Nov 10, 2019 Nov 10, 2019
Ok, I came across the util.printf but was not able to control the thousand separator.
Please can you confirm that the formattedValue property in no longer functional or if it has a substitution new property?

Thanks
Translate
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 ,
Nov 10, 2019 Nov 10, 2019

I have never seen a property with the name formattedValue.

Translate
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 ,
Nov 10, 2019 Nov 10, 2019

Here is some old reference to the formattedValue property:

 

https://blogs.adobe.com/formfeed/2011/06/understanding-field-values.html

 

Is there a way to control the thousand separator through util.printf?

 

Thanks 

Translate
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 ,
Nov 10, 2019 Nov 10, 2019

util.printf uses the format specs of C/C++.

Translate
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 ,
Nov 10, 2019 Nov 10, 2019

Hello,

 

I was trying to fix the decimal and thousand separator issues but I coudn't figure it out.

It is not possible to change the decimal symbol from dot to comma without changing the location settings, but this doesn't seem to work in Acrobat JS.

The argument for the thousand separator %,d doesn't work either.

 

Any suggestion?

 

Translate
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 ,
Nov 10, 2019 Nov 10, 2019

What format does you use in the form?

Translate
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
LEGEND ,
Nov 10, 2019 Nov 10, 2019

I found those three values discussed here https://blogs.adobe.com/formfeed/2011/06/understanding-field-values.html in the context of XFA (LiveCycle Designer) forms - though the blog post at no point mentions that! That will do no good for Acrobat forms.

Translate
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 ,
Nov 10, 2019 Nov 10, 2019

Ok, it's clear thanks.

 

Is there any equivalent in Adobe forms?

Translate
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 ,
Nov 11, 2019 Nov 11, 2019

Formatting in Acrobat forms is done with JavaScript.

Try the "util.printx()"function.

https://help.adobe.com/en_US/acrobat/acrobat_dc_sdk/2015/HTMLHelp/#t=Acro12_MasterBook%2FJS_API_Acro...

 

But the better function is "util.printf()"

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
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 ,
Nov 11, 2019 Nov 11, 2019

Hi,

 

Thanks, the link you provided is gold, it perfectly solved my problem.

 

I find however, that no direct way to extract a string as it is displayed in a field is a pity!

 

Thanks

Translate
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 ,
Nov 11, 2019 Nov 11, 2019
LATEST

Is this "formatted field value" used in other scripts that need the real value? If not, then just move the fomatting to the calculation. Then the real value is the formatted value. 

 

If the real value is needed, you can use a two field solution, a hidden field that contains the real value, and the visible field that contains the formatted value. 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
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