Warning

 

Close
Confirm Action

Are you sure you wish to do this?

Cancel Confirm
AR15.COM
2/18/2015 11:59:10 PM EDT
I posted this in Urban Commandos but there is much more traffic here.


I want to add JS to a PDF file that I have created. The point of the JS is too subtract 16 days from the input date.

aka
Start date 15 May 15
Suspense date 29 April 15



Anyone? I dont know a thing about JS.


Thanks!
2/19/2015 12:39:02 AM EDT
[#1]
I've never buried Javascript in a PDF, so I don't know what the input and output services look like.





In basic terms, all you need to do is to get the input date into a variable, date.parse it to get milliseconds since midnight, subtract an offset and output back in the proper locale format.





Do you know anything about the mechanics of putting Javascript into the PDF?
In HTML, this code provides a demo of calculating a negative 16 day offset:
<!DOCTYPE html>


<html>


<head>





<script language="JavaScript">





inputstr = "02/17/2015";





nd = new Date(Date.parse(inputstr) - 1380000000);





document.write(nd.toLocaleString());





</script>





</head>


<body>





</body>


</html>


 
2/19/2015 8:05:04 AM EDT
[#2]


Quoted:



I posted this in Urban Commandos but there is much more traffic here.
I want to add JS to a PDF file that I have created. The point of the JS is too subtract 16 days from the input date.





aka


Start date 15 May 15


Suspense date 29 April 15
Anyone? I dont know a thing about JS.
Thanks!
View Quote



This is probably the document that you seek:





http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/js_api_reference.pdf





What you are probably looking for (because I'm not going to read the whole document) is an event of some kind that would provide a suitable trigger - so some variation of "onLoad" or "onReady" or something along those lines. It wouldn't be suitable for document level scripting as it could potentially run before the page has finished loading, so it would try to add text to a field that isn't available yet.





Once you've found your event, you should probably be able to attach an action to that event. That action will involve your bit of javascript. I'm mostly guessing here because... well, because I'm not going to read the whole document and I've never actually tried to use JS in a PDF.





I believe one issue might be whether the PDF reader being used will support javascript. The most current Adobe Reader is pretty much guaranteed to do it, but if people are using older versions or a browser-based reader, who knows?





Edited to add:



OK, it turns out that "reading the post" really should come before "writing a reply" It looks like you should be able to check for event.commit on the input field, and when the commit is made, grab the input, run your magic script, and then send to the second field. So, start from event.commit and work your way forward from there.



Possibly.
 
2/19/2015 8:24:48 AM EDT
[#3]
I wouldn't even bother, since most JS in pdf files is disabled and never enabled by the user anyway, for the simple fact that it's a major gaping security hole.
2/19/2015 8:28:05 AM EDT
[#4]
Quote History
Quoted:
I wouldn't even bother, since most JS in pdf files is disabled and never enabled by the user anyway, for the simple fact that it's a major gaping security hole.
View Quote

THIS.

There is no fucking way I'd allow that, especially if I was using something as perpetually broken as Adobe Reader.
2/19/2015 11:04:59 AM EDT
[#5]
Quote History
Quoted:
I wouldn't even bother, since most JS in pdf files is disabled and never enabled by the user anyway, for the simple fact that it's a major gaping security hole.
View Quote



This is for an internal .mil document for my unit. Its a routing slip for actions.
2/19/2015 6:07:06 PM EDT
[#6]
Quote History
Quoted:



This is for an internal .mil document for my unit. Its a routing slip for actions.
View Quote View All Quotes
View All Quotes
Quote History
Quoted:
Quoted:
I wouldn't even bother, since most JS in pdf files is disabled and never enabled by the user anyway, for the simple fact that it's a major gaping security hole.



This is for an internal .mil document for my unit. Its a routing slip for actions.


An even better reason not to do it.
2/19/2015 9:55:17 PM EDT
[#7]
Quote History
Quoted:


An even better reason not to do it.
View Quote View All Quotes
View All Quotes
Quote History
Quoted:
Quoted:
Quoted:
I wouldn't even bother, since most JS in pdf files is disabled and never enabled by the user anyway, for the simple fact that it's a major gaping security hole.



This is for an internal .mil document for my unit. Its a routing slip for actions.


An even better reason not to do it.



I gave up on this. Thanks for the help to everyone though.
2/19/2015 10:03:00 PM EDT
[#8]
Nevermind
2/19/2015 10:10:10 PM EDT
[#9]

Quote History
Quoted:
I gave up on this. Thanks for the help to everyone though.

View Quote View All Quotes
View All Quotes
Quote History
Quoted:



Quoted:


Quoted:


Quoted:

I wouldn't even bother, since most JS in pdf files is disabled and never enabled by the user anyway, for the simple fact that it's a major gaping security hole.






This is for an internal .mil document for my unit. Its a routing slip for actions.





An even better reason not to do it.






I gave up on this. Thanks for the help to everyone though.





 
Do it in Excel and save to PDF.