Copy link to clipboard
Copied
I am working on a set of appendices where each appendix (which are several pages) need separate locking buttons.
I have a script for locking the entire document below. Is there a way to add script so that it only locks specific pages? I found adding f.page==0 can lock just the first page, but I would want to lock page 3, 4, and 5.
var nButton = app.alert({
cMsg: "Do you want to lock down and save this document?",
cTitle: "Form lockdown",
nIcon: 2, nType: 2});
if ( nButton == 4 ) {
for (var i=0; i<this.numFields; i++) {
var fname = this.getNthFieldName(i);
var f = this.getField(fname);
if (f.type!="button" && f.type!="signature") f.readonly = true;}
app.execMenuItem("SaveAs");
event.target.readonly = true;
}
Copy link to clipboard
Copied
Copy link to clipboard
Copied
The "page" property of the field is a good way to do this. But you have to be careful. If a field with the same name exists in more than one place (i.e. there is more than one "instance" of the field) then the page property is an array of page numbers.
But if you know that each field only has a single instance, then use the page property directly. In fact, you write a generic script that uses the page property of the "lock" button to lock fields on the same page.
if ((f.type!="button") && (f.type!="signature") && (f.page == event.target.page)) f.readonly = true;}
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
Thank you for this. To confirm however - is there a way to select multiple pages? the event.target.page only selects the page the button is placed on. I would like it to select that page, and the two before it.
Thank you
Copy link to clipboard
Copied
I've found JavaScript using nStart and nEnd but I can't find a way to add this into the original code without errors or it still locking the entire document.
And if I try to do multiple f.Page==1, f.page==2 etc. it doesn't do anything.
Any help is greatly appreciated as I am not strong in this!
Copy link to clipboard
Copied
What script does you use?
Copy link to clipboard
Copied
I tried this script adding the f.page== and adding multiple pages but it doesn't work.
var nButton = app.alert({
cMsg: "Do you want to lock down and save this document?",
cTitle: "Form lockdown",
nIcon: 2, nType: 2});
if ( nButton == 4 ) {
for (var i=0; i<this.numFields; i++) {
var fname = this.getNthFieldName(i);
var f = this.getField(fname);
if ((f.type!="button") && (f.type!="signature") && (f.page==4) && (f.page==5))f.readonly = true;}
app.execMenuItem("SaveAs");
event.target.readonly = true;
}
My goal is to only lock form fields on pages 2-5. Is there a way to script this?
Copy link to clipboard
Copied
Use a "or" like this:
&& (f.page==4 || f.page==5)
Copy link to clipboard
Copied
Use this:
&& (f.page>=1 && f.page<=4)
Copy link to clipboard
Copied
That worked!! Thank you so much!

