Skip to main content
Jo_2013
Known Participant
May 2, 2018
Answered

How to run a script after password security added to pdf

  • May 2, 2018
  • 1 reply
  • 659 views

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

This topic has been closed for replies.
Correct answer Joel Geraci

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.

1 reply

Joel Geraci
Community Expert
Joel GeraciCommunity ExpertCorrect answer
Community Expert
May 2, 2018

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.

Jo_2013
Jo_2013Author
Known Participant
May 2, 2018

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.