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

Locking form fields on specific pages

New Here ,
Jun 17, 2022 Jun 17, 2022

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
1.0K
Translate
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
1 ACCEPTED SOLUTION
Community Expert ,
Jul 06, 2022 Jul 06, 2022

Use this:

 

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

View solution in original post

Translate
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 17, 2022 Jun 17, 2022

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

Translate
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

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

Translate
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

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! 

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

What script does you use? 

Translate
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

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?

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

Use a "or" like this:

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

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

Use this:

 

&& (f.page>=1 && f.page<=4)
Translate
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
LATEST

That worked!! Thank you so much!

Translate
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