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

Trying to add a complex calculation to a PDF form

New Here ,
May 05, 2020 May 05, 2020

I've searched all over to find a solution to adding a complex calculation to a PDF form, but none have worked. Client is requesting a calculator to be included into a PDF to calculate altitude pressure for testing porposes on a ventilator. They currently have the calculations operating via Excel, but would like something more visually appealing. Obviously, formulas from Excel won't directly port over.

 

The calculation they are using within Excel is:

=((1-(0.000006783*A2))^5.256) 

A2 being the variable input, of course.

 

My main question is, can Acrobat perform this type of calculation? My assumption is that the operators, particularly for the exponent, may not translate. These numbers are rigid, so they cannot be simplified. If that is an issue, I can certainluy forward that info back to the client.

 

Huge thanks in advance,

Kyle

TOPICS
How to , PDF forms
3.2K
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 ,
May 06, 2020 May 06, 2020

Try this:

event.value =  Math.pow(1-0.000006783*this.getField("Altitude").value, 5.256); 

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 ,
May 05, 2020 May 05, 2020

Yes, check out the Math object in JavaScript. 

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/pow

 

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 ,
May 06, 2020 May 06, 2020

Thanks for your reply Thom_Parker. Unfortunately, it appears that Acrobat does not recognize Math object. That, or I am applying it wrong.

 

According to that guide, my formula should look like: (Math.pow(1-(0.000006783*Altitude)), 5.256); or Math.pow(1-(0.000006783*Altitude)), 5.256;. Neither of which will provide a result. Even a simple equation, such as: Math.pow(Altitude, 2); will not produce a result. Removing the exponent altogether does give me an answer though, (1-(0.000006783*Altitude)). The exponent is crucial to this working, obviously.

 

When building my form, I am placing the formula into the Simplified field notation under calculation, as this is where all other formulas are placed.

 

Any chance you see an obvious mistake in my equation?

 

Thanks in advance,

Kyle

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 ,
May 06, 2020 May 06, 2020

You must use Javascript for the use of Math.pow

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 ,
May 06, 2020 May 06, 2020

Thanks,

 

I figured I was using Javascript, as the field editor states that it is editing Javascript. Do I need to wrap this in a <script>? I'm sorry, in advance, for my questions. I'm not as well versed in Javascript and this really is a one off.

 

According to Acrobat documentation, the Exponent Operator should be ^ (as opposed to Math.pow), but that does not seem to work either.

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 ,
May 06, 2020 May 06, 2020

Try this:

event.value =  Math.pow(1-0.000006783*this.getField("Altitude").value, 5.256); 

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 ,
May 06, 2020 May 06, 2020

Success! That appears to work. Thank you so much. I owe you big time.

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 ,
Dec 23, 2021 Dec 23, 2021
LATEST

Same question but more to the fields within a form.

Essentially (Counted Quantity - System Quantity) x Unit Price = Extended Price

 

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