5 Replies Latest reply on Sep 19, 2013 4:15 AM by Rahul Arya

    Creating a watermark script

    Rahul Arya

      Hi - I am trying to create a script to add a watermark to all the masterpages of a document. I am trying to create a function which adds a text frame to a layer called watermark. The script is as below


      var myDocument=app.activeDocument;

      var myPages = app.activeDocument.pages;

      var myPage = app.activeDocument.pages.item(0);

      var myMasterSpread=myDocument.masterSpreads.everyItem();

      var myMasterLength = app.activeDocument.masterSpreads.length;

      var myTextFrame;


      //Creating a layer called watermark and moving it to the end




          var myLayer=myDocument.layers.add();

          myLayer.name = "watermark";






          var myLayer=myDocument.layers.item(0);




      //creating function for watermark

      function watermark()


          myTextFrame=myMasterSpread.textFrames.add({contents: "DRAFT", rotationAngle:45, geometricBounds: [190, 70, 220, 195]});




      watermark ();


      This is working fine. But I am unable to change the font, point size of the text frame.

      I can add the same if I am not creating a function with the following script but it does not work when I add it to the above function.

      It just runs and throws no error.


      var myTextObject = myTextFrame.parentStory.paragraphs.item(0);

      myTextObject.appliedFont = app.fonts.item("Times New Roman");


      myTextObject.fillColor=myDocument.colors.add({name:"test", model:ColorModel.process, colorValue:[0, 0, 0, 12]});


      Any help would be greatly appreciated




      Rahul Arya

        • 1. Re: Creating a watermark script
          Trevorׅ Adobe Community Professional

          look at the DocumentWatermark.jsx  sample that comes with indesign


          function main(){
          function mySetup() {
              var myDocument = app.documents.add();
              myDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.points; 
              myDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.points; 
              myDocument.documentPreferences.pageHeight = 792; 
              myDocument.documentPreferences.pageWidth = 612; 
              var myTextFrame = myDocument.pages.item(0).textFrames.add({geometricBounds:[36, 36, 756, 576], contents:TextFrameContents.PLACEHOLDER_TEXT});
          function mySnippet() {
              var myDocument = app.documents.item(0);
              myDocument.watermarkPreferences.watermarkVisibility = true;
              myDocument.watermarkPreferences.watermarkDoPrint = true;
              myDocument.watermarkPreferences.watermarkDrawInBack = true;
              myDocument.watermarkPreferences.watermarkText = "Confidential";
              myDocument.watermarkPreferences.watermarkFontFamily = "Arial";
              myDocument.watermarkPreferences.watermarkFontStyle = "Bold";
              myDocument.watermarkPreferences.watermarkFontPointSize = 72;
              myDocument.watermarkPreferences.watermarkFontColor = UIColors.blue; 
              myDocument.watermarkPreferences.watermarkOpacity = 60;
              myDocument.watermarkPreferences.watermarkRotation = -45;
              myDocument.watermarkPreferences.watermarkHorizontalPosition = WatermarkHorizontalPositionEnum.watermarkHCenter;
              myDocument.watermarkPreferences.watermarkHorizontalOffset = 0;
              myDocument.watermarkPreferences.watermarkVerticalPosition = WatermarkVerticalPositionEnum.watermarkVCenter;
              myDocument.watermarkPreferences.watermarkVerticalOffset = 0;
          function myTeardown() {
          • 2. Re: Creating a watermark script
            Rahul Arya Level 1

            Dear Trevor - Thanks for the script. It works well but the only problem with this is the opacity of watermark is not maintained while printing the document. It comes as very dark and makes the text difficult to read. Any help on this?




            Rahul Arya

            • 3. Re: Creating a watermark script
              Laubender Adobe Community Professional & MVP

              Using a different color could help…


              Perhaps a "UIColors.LIGHT_GRAY" will do the job?


              Or you could define your own RGB color like that:




              (a very light gray defined as an array of reals for R, G, B)


              What version of InDesign do you use?



              • 4. Re: Creating a watermark script
                Rahul Arya Level 1

                Yes, I used [227,227,227].. Worked perfect. Thanks


                I use CS 6.


                Any idea why the following did not work in function.


                var myTextObject = myTextFrame.parentStory.paragraphs.item(0);

                myTextObject.appliedFont = app.fonts.item("Times New Roman");




                • 5. Re: Creating a watermark script
                  Rahul Arya Level 1

                  I have 1 more question - How can we do this in page Maker?

                  I am using Adobe PageMaker 7.0