These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Is it possible to remove watermarks programatically?

StevenD
Registered: Oct 6 2006
Posts: 368
Answered

I just found out how to add a watermark to a document (addWatermarkFromText method) and it works great. But what if I want to remove the watermark at a later date. I don't seem to be able to remove the watermark I added via JavaScript by going to Document > Watermark > Remove. The only way I can see to remove it is by selecting the Touchup Object tool and manualy deleteing the watermark from each page.

Is there a way to get rid of them with JavaScript like you can add them with JavaScript.

StevenD

My Product Information:
Acrobat Pro Extended 9.0, Windows
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
You will need to manipulate the "state" property of the "Watermark" OCG object.

function SetWatermarkState(doc, bState) {
/* set the "Watermark" to bState for doc
doc - doc objet to process
bState - value for logical state
true = show
false = hide
*/

var ocgArray = doc.getOCGs();
for (var i=0; i < ocgArray.length; i++) {
if (ocgArray[i].name == "Watermark") {
ocgArray[i].state = bState;
} // end if Watermark
} // end loop through the OCG object
return;
} // end SetWatermarkState function

SetWatermarkState(this, false);

George Kaiser

UVSAR
Expert
Registered: Oct 29 2008
Posts: 1357
Bear in mind the JS snippet above doesn't "remove" anything - it just sets it to invisible, so there may still be a downstream issue if the watermark contained something you really don't want to share!
StevenD
Registered: Oct 6 2006
Posts: 368
Right. I want to remove it completely not just hide it. I wonder why I can add a watermark with JavaScript yet the menu item to remove it dosen't work. Unless maybe I'm leaving something out of the code below.

this.addWatermarkFromText({
cText: "DRAFT",
cFont: font.HelvB,
bOnTop: false,
nScale: -.8,
nRotation: 45,
nOpacity: .4
});

If I add another watermark using the UI so there are now two watermarks and select Document > Watermark > Remove and click Ok both watermarks are removed.

StevenD

George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1875
Have you read this:

http://www.acrobatusers.com/tech_corners/javascript_corner/tips/2006/create_use_layers/
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
There is no JavaScript method to remove a watermark, so you only have the abiltiy to change its state without any interaction. You could also execute the menu item to remove the watermark, but you will still have to deal with the conformation window. And then there is the redaction approach but you have to find, mark and apply.

George Kaiser

StevenD
Registered: Oct 6 2006
Posts: 368
I thought about trying to use execute menu item but I think Acrobat has made it harder to get to some of menu items. At least if I am looking at it right the number of menu items that are easy to get to have dwindled in number over the past two versions.

But. I it is a good suggestion and I will take a look at it. I would be ok with dealing with the confirmation window. In fact I'm Ok using the UI to work with watermarks it is just some of the other folks at work who have a hard time with multiple step operations that I have set up a custom tool bar button so all they have to do is click the button to put the DRAFT water mark on page.

I think there needs to be either a JS method to assist in removing a watermark or the UI recognize that there really is a watermark there.

Thanks everyone for helping out on this. I really do appreciate it.

StevenD

hitsugaya_taicho
Registered: Sep 22 2011
Posts: 1
George

Thank you for the script. I relatively new to scripting and used your script. Unfortunately, it only removes the watermark on the first page only and not the entire document. How can I remove the watermark in all of the pages.

Edwin Mendoza


try67
Expert
Registered: Oct 30 2008
Posts: 2398
You need to find out what their names are. All watermarks added by Acrobat will be called "Watermark".

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com