8 Replies Latest reply on Jun 22, 2015 3:00 PM by nodro

    How can I use JavaScript system functions to get date from NTP Server? Thanks

    noeld6761823 Level 1

      Hello I have been coding in JavaScript that is part of the Adobe Acrobat DC software. I want to program a pdf that can open up until an expiration date. I have figured out how to write this but the time is local to the computer which can be changed. I want to be able to call to a NTP server to get the time from it. The NTP server as I have read is a TCP/IP Protocol that transports packets from http.

       

       

      I can connect to the server right now but do not know how to parse through to extract the time. Here is what I have:

       

      app.launchURL("http://time-d.nist.gov",false); //false to open the browser in a window

      (maybe) var time = new date();

      time = ?;      //value from the server that is open

       

       

      Is there a way with just normal JavaScript (No Jquery, AJAX, .js, etc.) to extract the date from a NTP server. I would prefer it in the Adobe syntax if that is possible though. Thank you so much!

        • 1. Re: How can I use JavaScript system functions to get date from NTP Server? Thanks
          Test Screen Name Most Valuable Participant

          No, you cannot get a response from a NTP server (didn't I say that?), and you cannot get any connection from anything launched by launchURL. You also cannot use JQuery or AJAX - these are HTML related technologies.

           

          You can submit a form. This requires YOU to provide software on YOUR web server to respond with the date in a suitable format (unless you can find a time providing server that responds to HTTP post with suitable responses that you can parse).

          • 2. Re: How can I use JavaScript system functions to get date from NTP Server? Thanks
            noeld6761823 Level 1

            Hello Test Screen Name,

             

            Sorry to keep annoying you. I am just shooting in the dark of how I can get the time constant on the local computer or elsewhere for the pdf. I am interning for a small company that really can't shell out the money for DRM services per month. They want me to code this basic communication and I have no scripting, browser, or network experience. Just Java, C++, VB, etc. I just started using adobe acrobat and learned JavaScript(which isn't too different to java) last week. Thank you for being so patient with me

             

            -Can you give me a link to this form you are talking about if it has a guide. I went to edit > preferences > forms > but did not understand what you guys were saying in the last post.

            -I also researched online and you know how asking google or any search engine with basic terms is.

            -The more details the better

             

            If I don't go down the form direction you are talking about, do you think that LiveCycle would be anymore help to me? I heard some rumors that it is a little more powerful for scripting and easier to manipulate a pdf.

             

            Thanks again for your help and everyone else too! This community has been a great friend.

            -Noel

            • 3. Re: How can I use JavaScript system functions to get date from NTP Server? Thanks
              gkaiseril MVP & Adobe Community Professional

              There is no absolute way to accomplish what you want because you will need to use Acrobat JavaScript to test the if the expiration date has passed and any user can easily turn off the use of JavaScript in Acrobat/Reader.

               

              I would look at using layers. Open the form with a blank page or any page but not the form. Then use a document level script to hide that layer and display the form layer. If JavaScript is turned off the form layer will not display. You could also over the form with a large read only hidden field and hide the field if the expiration date has not been passed.

              • 4. Re: How can I use JavaScript system functions to get date from NTP Server? Thanks
                noeld6761823 Level 1

                That is an ingenious idea which I most likely will use for testing whether the JavaScript is turned off. However, can't the viewer still change the time locally on the computer and trick the script into thinking it's a different date? If so do you think I can code the document script to communicate with a script outside the document to get the date from a http protocol and pass that value as a parameter for the pdf scripts? I know it's far out there and confusing (step by step below)

                 

                javascript(outside acrobat invokes function and variable parameter)>>gets date and saves to ref var passed>> document script automatically changes variable time b/c ref>> pdf script uses global variable >> real time achieved! idk maybe

                 

                As Test Screen Name said "You also cannot use JQuery or AJAX [for Adobe]". However this would allow to run these types of javascript and get the date.

                 

                From Entering Document Scripts

                " Any functions or variables defined in a document script are visible to every other script in the PDF, so they can also be considered the document’s global area. If a document discloses itself to Acrobat, then scripts outside the document can also see and use variable and functions defined here. Disclosure means the document’s disclosed property is set to true."

                https://acrobatusers.com/tutorials/js_document_scripts


                This would be great if it were passed as a reference variable. Right?

                • 5. Re: How can I use JavaScript system functions to get date from NTP Server? Thanks
                  noeld6761823 Level 1

                  I am unsure what you mean GKaiseril about using layers. When I use the form shortcut that is the only pdf that's usable. Even saves in a different name or overwrites the other layer file.

                  • 6. Re: How can I use JavaScript system functions to get date from NTP Server? Thanks
                    Test Screen Name Most Valuable Participant

                    What do you mean by "layer file"? Layers are something entirely INSIDE a single PDF.

                     

                    But let's look at the big picture. Are you saying that you can have the end user install software on the computer, have them run your software and have that open the PDF? If so, you can have an external app that refuses to open the file - but of course once opened it can be saved. 

                    • 8. Re: How can I use JavaScript system functions to get date from NTP Server? Thanks
                      nodro Level 1

                      Haha yeah  sorry... that was stupid... got it to work. Do you guys think there is any other way other than time and certificates with their adobe ids that I can make the pdf "self destruct" so to speak when I want it to for the users.