Skip to main content
Participant
September 17, 2013
Question

Creating a watermark script

  • September 17, 2013
  • 1 reply
  • 2065 views

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

try

    {

    var myLayer=myDocument.layers.add();

    myLayer.name = "watermark";

    myLayer.move(LocationOptions.AT_END);

    }

catch(e_layer)

    {

    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]});

    myTextFrame.itemLayer=myDocument.layers.item("Watermark");

    };

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.pointSize=105;

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

Any help would be greatly appreciated

Thank

Rahul Arya

This topic has been closed for replies.

1 reply

Trevor:
Legend
September 17, 2013

look at the DocumentWatermark.jsx  sample that comes with indesign

main();

function main(){

    mySetup();

    mySnippet();

    myTeardown();

}

//<setup>

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});

}

//</setup>

//<snippet>

function mySnippet() {

    //<fragment>

    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;

    //</fragment>

}

//</snippet>

//<teardown>

function myTeardown() {

}

//</teardown>

Participant
September 18, 2013

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?

Thanks

Rahul Arya

Community Expert
September 19, 2013

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:

[246,246,246]

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

What version of InDesign do you use?

Uwe