Skip to main content
Participant
December 30, 2019
Answered

PDF automation - JS script

  • December 30, 2019
  • 1 reply
  • 1037 views

Hi!

I want to do such a thing:
- add the active field (click) to a specific place in the PDF file (button - I know how to do it)
- create a script in JS that will show me the number of today (e.g. 320 day this year)
- move to a specific page (the result of the script No. 1) - e.g. to page 320

 

Could you help me with these scripts?

Thanks!

This topic has been closed for replies.
Correct answer try67

Not sure what you mean by the first point.

Where do you want to show this number?

 

You can use something like this:

 

var now = new Date();
var start = new Date(now.getFullYear(), 0, 0);
var diff = (now - start) + ((start.getTimezoneOffset() - now.getTimezoneOffset()) * 60 * 1000);
var oneDay = 1000 * 60 * 60 * 24;
var day = Math.floor(diff / oneDay);
this.pageNum = day-1;

 

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
December 30, 2019

Not sure what you mean by the first point.

Where do you want to show this number?

 

You can use something like this:

 

var now = new Date();
var start = new Date(now.getFullYear(), 0, 0);
var diff = (now - start) + ((start.getTimezoneOffset() - now.getTimezoneOffset()) * 60 * 1000);
var oneDay = 1000 * 60 * 60 * 24;
var day = Math.floor(diff / oneDay);
this.pageNum = day-1;

 

karol22oAuthor
Participant
January 1, 2020

Thank you @try67 That's what I needed 🙂
I run this script after clicking the active field (link) and it works great ... but only in Adobe Acrobat.

Is it possible to run JS scripts in other apps as well? For example standard Apple Preview.

 

Thank you for your help!

try67
Community Expert
Community Expert
January 1, 2020

That's up to the developers of those applications. Apple Preview is known to be a very bad application, and it corrupts PDF forms just by opening them. I would recommend you don't use it at all.