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

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

New Here ,
Mar 21, 2017 Mar 21, 2017

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?

TOPICS
PDF forms

Views

20.8K

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

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;

}

Votes

Translate

Translate
Community Expert ,
Mar 24, 2021 Mar 24, 2021

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

Votes

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

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

Votes

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

Copy link to clipboard

Copied

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

 

Votes

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

Copy link to clipboard

Copied

Add the same line for other fields.

Votes

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

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

 

Votes

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

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

Votes

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

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? 

Votes

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

Copy link to clipboard

Copied

Sure. Just change this line:

f.readonly = true;

To:

f.readonly = false;

Votes

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

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

 

Votes

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

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

Votes

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

Copy link to clipboard

Copied

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

Votes

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

Copy link to clipboard

Copied

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

Votes

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

Copy link to clipboard

Copied

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

Votes

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

Copy link to clipboard

Copied

Thank you.

Votes

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

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.

Votes

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

Copy link to clipboard

Copied

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

Votes

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

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.

 

Votes

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

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.

Votes

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

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;

Votes

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