• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
2

Protect PDF document with Javascript

Participant ,
Jun 23, 2020 Jun 23, 2020

Copy link to clipboard

Copied

How to password protect(take off) PDF document using Javascript code?

Pre-created a protection policy with the name "MySecurityPol", and run this code from the console in Acrobat Pro DC, but there is a syntax error! What am I doing wrong?

var DoApplyMySecurity = app.trustedFunction( function(){
    var oMyPolicy = null;    app.beginPriv();
    // First, Get the ID of My Security Policy
    var aPols = security.getSecurityPolicies()
    for(var index=0;index<aPols.length;index++){
        if(aPols[index].name == "MySecurityPol"){            oMyPolicy = aPols[index]; break;
        }
    }
    if(oMyPolicy == null){ app.alert("Policy Not Found"); return; }
    // Now, Apply the security Policy
    var rtn = this.encryptUsingPolicy({oPolicy: oMyPolicy });
    if(rtn.errorCode != 0) app.alert("Security Error: " + rtn.errorText); app.endPriv();
});
I want to put a code in the form field to protect the document, when I click on the form, the code is launched and the document is encrypted.
TOPICS
Acrobat SDK and JavaScript

Views

1.5K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 23, 2020 Jun 23, 2020

Copy link to clipboard

Copied

I'm not getting any syntax errors for this code. What is the full text of the error message?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 24, 2020 Jun 24, 2020

Copy link to clipboard

Copied

Sorry for the absence, it looks like an error if you run the code from the console

1.png

if you put the code in the button form field, then the error looks like this

Screenshot_2.png

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 25, 2020 Jun 25, 2020

Copy link to clipboard

Copied

LATEST

Does you select the whole script when you execute it in the console?

 

You can't define a trusted function in a field button. You must put in a folder level script.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines