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

How to "lock" the form after filling it with the reader version?

New Here ,
Mar 21, 2017 Mar 21, 2017

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?

TOPICS
PDF forms
24.5K
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 ,
Mar 21, 2017 Mar 21, 2017

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;

}

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 ,
Mar 24, 2021 Mar 24, 2021

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;
}
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 ,
Mar 24, 2021 Mar 24, 2021

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

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 ,
Jun 25, 2021 Jun 25, 2021

Hi This is brilliant - How would you add a number of fields to leave open?

 

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 25, 2021 Jun 25, 2021

Add the same line for other fields.

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 ,
Jun 25, 2021 Jun 25, 2021

ok can I only disable a handful of fields instead, please help me with the syntax I am still very new at JS

 

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 25, 2021 Jun 25, 2021

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".

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 27, 2022 Jul 27, 2022

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? 

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 27, 2022 Jul 27, 2022

Sure. Just change this line:

f.readonly = true;

To:

f.readonly = false;

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 27, 2022 Jul 27, 2022

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"];

 

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 ,
Aug 22, 2021 Aug 22, 2021

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

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 ,
Aug 23, 2021 Aug 23, 2021

You can specify as many field names as you wish in the fieldsToSkip array...

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 ,
Jun 01, 2022 Jun 01, 2022

How do I remove the readonly to get back into my document?

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 02, 2022 Jun 02, 2022

Change "true" to "false" (without the quotes) in the last line of code above.

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 ,
Jun 02, 2022 Jun 02, 2022
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
Community Expert ,
Jun 02, 2022 Jun 02, 2022

Can't you read this topic to the end before posting?
The answer to your question has been below for over two years.


Acrobate du PDF, InDesigner et Photoshopographe
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 23, 2024 Jul 23, 2024
LATEST

Is there a code that I can use to "Unlock it?" I want to create a button that gives the option to unlock and make edits, while also having the mentioned above code for "lock" 

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 ,
Sep 17, 2018 Sep 17, 2018

Although this is marked as Not Answered, the instructions work like a charm!  Exactly what I needed.

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 ,
May 18, 2020 May 18, 2020

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.

 

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
LEGEND ,
May 18, 2020 May 18, 2020

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.

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 ,
May 18, 2020 May 18, 2020

"Is it possible to reverse the read only after the scritp is run?"

Yes.

Replace this line:

f.readonly = true;

 

By:

f.readonly = false;


Acrobate du PDF, InDesigner et Photoshopographe
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