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

Adding watermarks with customization

ACat299612
Registered: May 31 2011
Posts: 14
Answered

Hi,
I am new to these forums and Adobe Acrobat. I am trying to automate a process my company is using, and would like to be pointed in the correct direction. I hope this is the correct forum to start with.
 
Basically, I have a pdf that I want to add a watermark to, but I want to do this 5-10 times, and also change the text each time in the watermark. Something like "This document is for the use of ". The 5-10 's would reside in a file on disk.
 
What is the best method to implement a process like this? Any advice is appreciated.
 
Thanks
 
Alan

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Read These three articles:

http://acrobatusers.com/tutorials/2006/create_use_layers
http://acrobatusers.com/tutorials/watermarking-pdf-javascript
http://acrobatusers.com/articles/getting-external-data-acrobat-x-javascript

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

ACat299612
Registered: May 31 2011
Posts: 14
Thom,
Thanks for the info. I believe I have everything basically working with one problem. As you stated in your section on watermarks, adding a new watermark adds to the existing. So, after the first pass of the original pdf, the watermarks get overlayed on top of each other. I looked for some info on the OCG's, but I believe you cannot delete OCG's through javascript. So, do I have to close the orignial pdf and open it again each time for each user? If so, how do I do this, as I could not find a way or opening and closing pdf's. Or, did I miss something with the OCG?
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
You are correct that an OCG cannot be deleted using a script:( There are a few things missing from the OCG functionality that make working with them awkward. But you can rename an OCG so it's no longer part of the "Watermarks", and then hide it. Actually renaming them up front after the watermark is created is a good idea so a specific OGC is easy to find and manipulate.

Opening and closing a PDF is done with the "app.openDoc()" and "doc.closeDoc()" functions.


Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

ACat299612
Registered: May 31 2011
Posts: 14
I am trying to use the open and close functions and ran into a problem. The first watermark got added fine and I saved it using the saveAs function. My code then closed the doc using this.closeDoc and opened the original using app.openDoc. When I try to add the next watermark, I get a DeadObjectError: Object is dead on the this.addWatermarkFromText call. I must be missing something, so any help is appreciated.

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Accepted Answer
You have to be very careful with how you use the "this" keyword. If the script closed the current PDF (generally a bad idea) then the "this" keyword has no context, hence the "DeadObjectError". If the script opened a PDF using app.openDoc then it must use the doc object returned by that function. "app.openDoc" must be called from a trustedFunction.


Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

ACat299612
Registered: May 31 2011
Posts: 14
Got it working. Thanks for your help Thom.