Skip to main content
Participant
February 8, 2022
Answered

Can I use cosine and sin functions in a custom calculation script?

  • February 8, 2022
  • 2 replies
  • 987 views

I'm trying to write a javascript calculation in a PDF form using cos and sin functions but I can't get javascript math functions to work.  Any suggestions?

This topic has been closed for replies.
Correct answer Bernd Alheit

Javascript is case-sensitive. Use Math. not math. 

2 replies

Participant
February 8, 2022

No, I can't get it work.

 

I tried something simple like:

 

event.value=math.cos(0);

and

event.value=math.PI

 

but it didn't return anything.  No error either, it just didn't change the cell value from the last java formula I entered that did work.

 

Bernd Alheit
Community Expert
Bernd AlheitCommunity ExpertCorrect answer
Community Expert
February 8, 2022

Javascript is case-sensitive. Use Math. not math. 

Participant
February 8, 2022

That was simple, thanks!  

 

Here's the formula I'm using for converting a magnitude and angle to the X coordinate and it works great now:

 

event.value=this.getField("Magnitude”).value*Math.cos(this.getField("Angle").value/(180/Math.PI));

Thom Parker
Community Expert
Community Expert
February 8, 2022

What do you mean you can't get them to work?  Here's the reference.

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

 

 

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