Copy link to clipboard
Copied
I have a document which is placed on the company intranet (it needs to be password protected), if a copy is downloaded, the next time it is opened a watermark will show on each page.
The script is placed as an action on the page open event.
this.addWatermarkFromText("Uncontrolled document", 0, font.Helv, 24, color.red);
This script works however once the pdf is password protected it will no longer run the script.
NotAllowedError: Security settings prevent access to this property or method.
Doc.addWatermarkFromText:1:Page undefined:Open
Can anyone please advise how an embedded javascript can run after the document is password protected?
Thanks
You're confusing two different things.
JavaScript can absolutely run on a document after it has been password protected. However, JavaScript can't modify the document in ways that the protection prohibits... just like if you had manually tried to add a watermark.
In short, you won't be able to add a watermark after the document has been protected.
What you can do instead is put a button field over the entire page that and then use a script to control it's visibility. The button icon would be a PDF
...Copy link to clipboard
Copied
You're confusing two different things.
JavaScript can absolutely run on a document after it has been password protected. However, JavaScript can't modify the document in ways that the protection prohibits... just like if you had manually tried to add a watermark.
In short, you won't be able to add a watermark after the document has been protected.
What you can do instead is put a button field over the entire page that and then use a script to control it's visibility. The button icon would be a PDF of the watermark you want. Because the field will always appear on top of the page content, you'll want to make it somewhat transparent as well.
Copy link to clipboard
Copied
Thank you for your assistance Joel. I added a button the same size as the pdf page and used the following page open action script. var f = this.getField("Button"); f.display = display.visible It works perfectly, much appreciated.