11 Replies Latest reply on Oct 17, 2008 8:17 AM by (shivaji_pokala)

    Add UserID to Printed PDF file

      I have javascript that prints some text and a date stamp on each page of a pdf file. Now the Management wants this information to include the persons id that is logged onto the computer from which the pdf file was printed.
        • 1. Re: Add UserID to Printed PDF file
          gkaiseril MVP & Adobe Community Professional
          As documented in Adobe's Acrobat JavaScripting Manual, there are security restrictions with respect to the "identity" object. Those restrictions prevent one from directly accessing the "identity" object from a form field. You can access the properties from a folder level JavaScript. The following script when placed in Acrobat's application JavaScript folder will create and initialize application level variables that be accessed by any PDF opened by Acrobat:

          // Folder level script to create an application level variables for the "identity" objects properties
          var Identity = new Array();
          Identity.Corporation = identity.corporation;
          Identity.Email = identity.email;
          Identity.LoginName = identity.loginName;
          Identity.Name = identity.name;

          // or
          var Identity = new Array();
          for (i in identity)
          Identity.i = identity.i;

          One can then add the following document level or field level javaScript to initialize fields within the PDF to the value of the application level variables:

          this.getField("loginName").value = Identity.LoginName;
          this.getField("name").value = Identity.Name;
          this.getField("by").value = "By: ";
          this.getField("by").value += Identity.Name;

          With version 7.0 or above, you can use a trusted function located as a document level script to retrieve the information:

          trustedIdentity = app.trustedFunction( function (sProperty) {
          var iProperty = "";
          app.beginPriv(); // explicitly raise privilege
          iProperty = identity[sProperty];
          app.endPriv();
          return iProperty;
          })

          One can then add the following document level or field level javaScript to initialize fields within the PDF to the value of the application level variables:

          this.getField("loginName").value = trustedIdentity("loginName");
          this.getField("name").value = trustedIdentity("name");
          this.getField("by").value = "By: ";
          this.getField("by").value += trustedIdentity("name");
          • 2. Re: Add UserID to Printed PDF file
            Level 1
            I get this message when trying your second suggestion.

            NotAllowedError: Security settings prevent access to this property or method.
            app.trustedFunction:1:Document-Level:Status0

            Here is part of my JavaScript. I am running Acrobat 8

            //-------------------------------------------------------------
            //-----------------Do not edit the XML tags--------------------
            //-------------------------------------------------------------

            //
            //Status0
            //
            /*********** belongs to: Document-Level:Status0 ***********/
            trustedIdentity = app.trustedFunction( function (sProperty) {
            var iProperty = "";
            app.beginPriv(); // explicitly raise privilege
            iProperty = identity[sProperty];
            app.endPriv();
            return iProperty;
            })
            var lin = trustedIdentity("loginName");
            var cDate = util.printd("mm/dd/yyyy hh:MM:ss tt" , new Date()); var f = this.getField("Status0");f.value = "Released - Printed: " + lin + cDate;
            //

            //
            • 3. Re: Add UserID to Printed PDF file
              Patrick Leckey Level 3
              beginPriv() and endPriv() cannot be run from document-level functions, only from the folder-level.
              • 4. Re: Add UserID to Printed PDF file
                Level 1
                Message 1 lead me to believe different:

                With version 7.0 or above, you can use a trusted function located as a document level script to retrieve the information:

                I have tried to place code in Acrobat's application JavaScript folder but have not gotten it to work. Either I am placing it in the wrong place or something else is wrong.
                • 5. Re: Add UserID to Printed PDF file
                  Bernd Alheit Adobe Community Professional & MVP
                  No, you can't define a trusted function in a document. The method trustedFunction is available only during batch, console and application initialization events.
                  • 6. Re: Add UserID to Printed PDF file
                    Patrick Leckey Level 3
                    > The method trustedFunction is available only during batch, console and application initialization events.

                    And folder-level functions are loaded during application initialization. You need to put this in a folder-level function for it to work.
                    • 7. Re: Add UserID to Printed PDF file
                      Level 1
                      Okay, I got it to work. Now the bigger issue, will this folder-level function have to be done on every machine that will access the file that I want to display the user id of the current logged on user.
                      • 8. Re: Add UserID to Printed PDF file
                        Hello Steven,

                        I have the same requirement as yours and am very glad to find the answers here. Now I haven't seen an answer to the last question that you have posted in this thread, i. e., "will this folder-level function have to be done on every machine that will access the file". Can you please let me know if that indeed is the case ? Thanks in advance,

                        Shiva.
                        • 9. Re: Add UserID to Printed PDF file
                          gkaiseril MVP & Adobe Community Professional
                          If you click on the "Show All Messages" you will see all the post. My code needs to be placed in an "Application JavaScirpt" folder for Acrobat or Reader, and this code will need to be installed on each user's system or you can look at getting your form "Certified". See the Acrobat JS Reference for more information.
                          • 10. Re: Add UserID to Printed PDF file
                            (Aandi_Inston) Level 1
                            > "will this folder-level function have to be done on every machine that will access the file".

                            Folder level functions have to be installed on each machine. This is
                            absolutely necessary because the functions are bypassing the normal
                            security that protects users of Acrobat.

                            Aandi Inston
                            • 11. Re: Add UserID to Printed PDF file
                              Level 1
                              Thank you very much Geo and Aandi. Have a nice weekend.

                              Shiva