Locking form fields on specific pages

New Here ,
Jun 17, 2022 Jun 17, 2022

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;
}

 

TOPICS
Create PDFs , Edit and convert PDFs , How to , JavaScript , PDF forms

Views

81

Likes

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

correct answers 1 Correct answer

Adobe Community Professional , Jul 06, 2022 Jul 06, 2022

Use this:

 

&& (f.page>=1 && f.page<=4)

Likes

Translate

Translate
Adobe Community Professional ,
Jun 17, 2022 Jun 17, 2022

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;}

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Likes

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
New Here ,
Jul 04, 2022 Jul 04, 2022

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

Likes

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
New Here ,
Jul 05, 2022 Jul 05, 2022

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! 

Likes

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
Adobe Community Professional ,
Jul 05, 2022 Jul 05, 2022

Copy link to clipboard

Copied

What script does you use? 

Likes

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
New Here ,
Jul 05, 2022 Jul 05, 2022

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?

Likes

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
Adobe Community Professional ,
Jul 05, 2022 Jul 05, 2022

Copy link to clipboard

Copied

Use a "or" like this:

&& (f.page==4 || f.page==5)

Likes

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
Adobe Community Professional ,
Jul 06, 2022 Jul 06, 2022

Copy link to clipboard

Copied

Use this:

 

&& (f.page>=1 && f.page<=4)

Likes

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
New Here ,
Jul 06, 2022 Jul 06, 2022

Copy link to clipboard

Copied

LATEST

That worked!! Thank you so much!

Likes

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