3 Replies Latest reply on Jun 9, 2009 9:49 PM by Jo_2005

    Adding Document File Name to Stamp Script

    Jo_2005 Level 1

      Hello,

       

      I have the following script entered into the "custom calculation script" properties of a custom stamp.

       

      event.value = event.source.source.documentFileName;

       

      This script works fine and places the document file name on the stamp.

       

      eg document is called 6781202 Rev C.pdf and this appears on the stamp in the document.

       

      However the revision and the file extension are not required to be shown on the stamp

       

      Can any one help to amend the script to place the first part of the file name only on the stamp

       

      eg script modified to show document file name as 6781202.

       

      This script is to be used on multiple files and any help would be most appreciated.

       

      Thank you very much.

       

       

        • 1. Re: Adding Document File Name to Stamp Script
          try67 MVP & Adobe Community Professional

          Replace
          event.value = event.source.source.documentFileName;
          with
          firstWord = event.source.source.documentFileName.split(" ");
          event.value = firstWord[0];

          • 2. Re: Adding Document File Name to Stamp Script
            gkaiseril MVP & Adobe Community Professional

            To allow for a '.' in the file name before the file extension type:

             

            // get the file name and extension
            var sFullFileName =  this.documentFileName
            // make into an arry
            var aFullFileName = sFullFileName.split('.');
            // build a file name array dropping the extension
            var aFileName = new Array(aFullFileName.length - 2);
            for (i = 0; i < aFullFileName.length - 1; i++) {
            aFileName[i] = aFullFileName[i];
            }
            // recreate file name
            var sFileName = aFileName.join('.');
            console.println('"The file name of this document is '
            + sFileName +'."');

             

            You can add th additional code to check for the location of the string 'Rev' and strip those characters from the name.

            • 3. Re: Adding Document File Name to Stamp Script
              Jo_2005 Level 1

              Thank you very much for helping me with the script, it works perfectly in the stamp.

               

              I have been informed that the criteria has now been changed and the script needs to be placed in a text box rather than a stamp.

               

              I have adapted the script to insert a text box from "Batch Processing" and add a "calculation" set action to insert the first word of the file name.

               

              The problem is that the file name is not added by using the "Calculate" action automatically.

               

               

              // Create Text Box and insert the first word of a document name separated by a space

              var numpages = this.numPages;
              for (var i=0; i < numpages; i++)


              var f = this.addField("DocumentName", "text", 0,
              [60, 54, 135, 75]);

              f.setAction("Calculate","var f = this.getField('DocumentName'); firstWord = this.documentFileName.split (' '); f.value = firstWord[0];");

              f.textSize = 15;
              f.textColor = color.red;

               

               

               

              Can you possibly please advise where the script should be placed to automatically insert the file name, would it be in set action?

               

               

               

              Thank you very much for your valuable assistance.

               

               

               

               

              Message was edited by: Jo_2005