Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Try this:
event.value = Math.pow(1-0.000006783*this.getField("Altitude").value, 5.256);
Copy link to clipboard
Copied
Yes, check out the Math object in JavaScript.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/pow
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
You must use Javascript for the use of Math.pow
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Try this:
event.value = Math.pow(1-0.000006783*this.getField("Altitude").value, 5.256);
Copy link to clipboard
Copied
Success! That appears to work. Thank you so much. I owe you big time.
Copy link to clipboard
Copied
Same question but more to the fields within a form.
Essentially (Counted Quantity - System Quantity) x Unit Price = Extended Price

