Script a Watermark on all images on a layer
Looking for a script to add a watermark to all images on a particular layer in InDesign. Or is it possible to make an object style that includes a watermark and apply it to all images on a layer?
Looking for a script to add a watermark to all images on a particular layer in InDesign. Or is it possible to make an object style that includes a watermark and apply it to all images on a layer?
Hi @aaronf31067511, Try this—edit the "MyLayer" variable to the name of your image layer, and the "Mark" variable to the text you want for the mark.
//the name of the layer containing the images to mark
//edit as needed
var ln = "MyLayer"
//the watermark’s text
var wt = "Mark"
//the watermark layer
var mln = "WaterMarks"
var doc = app.activeDocument
var ag = doc.allGraphics;
//the mark content’s paragraph style
var ps = makeParaStyle(doc, "WaterMark")
ps.properties = {basedOn:"No Paragraph Style", pointSize:48, justification:Justification.CENTER_JUSTIFIED, fillColor:"Paper"}
//the mark’s text frame’s object style
var os = makeObjStyle(doc, "WaterMarks");
os.properties = {appliedParagraphStyle:ps, strokeColor:"None", strokeWeight:0, fillColor:"None"}
os.textFramePreferences.properties = {verticalJustification:VerticalJustification.CENTER_ALIGN};
os.contentTransparencySettings.blendingSettings.opacity = 70;
//a new layer for the mark
if (doc.layers.itemByName(mln).isValid) {
doc.layers.itemByName(mln).remove()
}
var wml = makeLayer(doc, mln)
//add the marks
var b, pp, wf;
for (var i = 0; i < ag.length; i++){
if (ag[i].constructor.name == "Image" && ag[i].itemLayer == doc.layers.itemByName(ln)) {
b = ag[i].parent.geometricBounds;
pp = ag[i].parentPage;
wf = pp.textFrames.add ({ geometricBounds: b, itemLayer:wml, fillColor:"None", appliedObjectStyle:os, contents:wt});
wf.texts.everyItem().appliedParagraphStyle = ps;
}
};
/**
* Makes a new named ParagraphStyle
* @ param the document to add the style to
* @ param style name
* @ return the new paragraph style
*/
function makeParaStyle(d, n){
if (d.paragraphStyles.itemByName(n).isValid) {
return d.paragraphStyles.itemByName(n);
} else {
return d.paragraphStyles.add({name:n});
}
}
/**
* Makes a new named ObjectStyle or returns an existing style
* @ param the document to add the style to
* @ param style name
* @ return the new object style
*/
function makeObjStyle(d, n){
if (d.objectStyles.itemByName(n).isValid) {
return d.objectStyles.itemByName(n);
} else {
return d.objectStyles.add({name:n});
}
}
/**
* Makes a new named Layer
* @ param the document to add the layer
* @ param layer name
* @ return the new layer
*/
function makeLayer(d, n){
if (d.layers.itemByName(n).isValid) {
return d.layers.itemByName(n);
} else {
return d.layers.add({name:n});
}
}
The script creates a Paragraph Style and Object Style for the watermark, which you could redefine as needed after running:

Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.