2 Replies Latest reply on Dec 10, 2014 1:29 PM by gkaiseril

    Javascript code to retrieve metadata - must run twice to work

    bkdu666

      Hi all

       

      This is frustrating the hell out of me. I've got a script to batch add headers/footers (via watermarks) to a range of pdf documents by using the respective document's metadata (title, subject).

       

      Checked everything: Script running ok, metadata all there and fine.

       

      However - I need to run the script twice in order for the metadata to be processed. What I mean: I open a given document, run the script on it and the metadata is not displayed in the header/footer. Save the document and close. I then run the script on the same document again and all works fine, i.e. the metadata title is displayed in the header and the metadata subject is displayed in the footer. Driving me nuts.

      What am I **** wrong? How can I get this to work on the first run? Guessing it might have to do with some specific form of variable declaration or pre-parsing the metadata?!

       

      Script below (please not, I've also tried declaring 2 variables and assigning the metadata title & subject to them, then calling those variables in the watermark statements ... same result):

       

      /* Batch Header - DocProp Title */

       

      var i = 0

       

      this.addWatermarkFromText({

          cText: this.info.title,

          nTextAlign: app.constants.align.center,

          cFont: "Century Gothic",

          nFontSize: 8,

          nHorizAlign: app.constants.align.center,

          nVertAlign: app.constants.align.top,

          nHorizValue: 10, nVertValue: -10,

              nScale: -1

      });

      this.addWatermarkFromText({

          cText: "Q-Pulse Id " + this.info.Subject,

          nTextAlign: app.constants.align.left,

          cFont: "Century Gothic",

          nFontSize: 8,

          nHorizAlign: app.constants.align.left,

          nVertAlign: app.constants.align.bottom,

          nHorizValue: 20, nVertValue: 10

      });

      this.addWatermarkFromText({

          cText: "Active 10/12/2014",

          nTextAlign: app.constants.align.center,

          cFont: "Century Gothic",

          nFontSize: 8,

          nHorizAlign: app.constants.align.center,

          nVertAlign: app.constants.align.bottom,

          nVertValue: 10

      });

       

      Hope someone can help with this. Guessing it's something simple code related that I'm not aware of - I'm a complete novice.