Copy link to clipboard
Copied
I have been making some PDF for my clients for them to edit information and after that, they send it to third part but, of course, need to "lock" the PDF after using a reader version. Is it possible?
Sure. You can use this code:
for (var i=0; i<this.numFields; i++) {
var f = this.getField(this.getNthFieldName(i));
if (f==null) continue;
f.readonly = true;
}
Copy link to clipboard
Copied
Sure. Try this:
for (var i=0; i<this.numFields; i++) {
var fname = this.getNthFieldName(i);
if (fname=="FieldNameXYZ") continue;
var f = this.getField(fname);
if (f==null) continue;
f.readonly = true;
}
Copy link to clipboard
Copied
Thanks a million for your fast reply 🙂
I'll test it and let you know the result.
In the meantime I got a different script from a friend and it works perfectly.
Tried to share it, but I get this error message from Adobe... so I can't...
Thank you again and kindest regards.
Stay safe,
Nuno
Copy link to clipboard
Copied
Hi This is brilliant - How would you add a number of fields to leave open?
Copy link to clipboard
Copied
Add the same line for other fields.
Copy link to clipboard
Copied
ok can I only disable a handful of fields instead, please help me with the syntax I am still very new at JS
Copy link to clipboard
Copied
You can do it like this:
var fieldsToSkip = ["FieldNameXYZ", "FieldNameABC", "FieldNameEFG"];
for (var i=0; i<this.numFields; i++) {
var fname = this.getNthFieldName(i);
if (fieldsToSkip.indexOf(fname)!=-1) continue;
var f = this.getField(fname);
if (f==null) continue;
f.readonly = true;
}
Edit the first line of code to include all the names of the fields that you don't want to "lock".
Copy link to clipboard
Copied
Thank you for this code! Super helpful. I was wondering though, is there a way to toggle between locking the form and unlocking the form?
Copy link to clipboard
Copied
Sure. Just change this line:
f.readonly = true;
To:
f.readonly = false;
Copy link to clipboard
Copied
Ohh!! This worked. For any newbie wondering, I created a "lock data" button and an "unlock data" button and with the unlocked version I put the above code, minus the below code... (and with false, of course). Thanks, try67!
var fieldsToSkip = ["FieldNameXYZ", "FieldNameABC", "FieldNameEFG"];
Copy link to clipboard
Copied
Thanks try67 for this
would clearfy this steps to get use will of your knowledge,
also need how about if we need to exclode more than one field from locking the form? can we get your support with this try67
thanks
Copy link to clipboard
Copied
You can specify as many field names as you wish in the fieldsToSkip array...
Copy link to clipboard
Copied
How do I remove the readonly to get back into my document?
Copy link to clipboard
Copied
Change "true" to "false" (without the quotes) in the last line of code above.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Can't you read this topic to the end before posting?
The answer to your question has been below for over two years.
Copy link to clipboard
Copied
Although this is marked as Not Answered, the instructions work like a charm! Exactly what I needed.
Copy link to clipboard
Copied
I know this is post is older yet it helped me do exactly what i needed at first. Is it possible to reverse the read only after the scritp is run? I've been unable to figure that out.
Copy link to clipboard
Copied
Run a similat script that sets readonly to false. Bear in mind there is no such thing as a form that can't be changed, if you are hoping for some kind of security.
Copy link to clipboard
Copied
"Is it possible to reverse the read only after the scritp is run?"
Yes.
Replace this line:
f.readonly = true;
By:
f.readonly = false;