These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Possible to make a filled-in form non-editable?

PeteA
Registered: Mar 16 2009
Posts: 6
Answered

Is it possible to create a form that allows a user with Reader to save a filled-in copy (by using "Extend Features In Adobe Reader") and to enable the user to then convert her saved copy to a non-editable document so that she can email it to 3rd parties who will not be able to make changes?

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Yes this is possible. If you can save a form from Reader then you can set the ReadOnly propertly of the form fields so that they are not editable. The best way to do this would be to create an automation tool loops through all the fields on a form and sets ReadOnly the fields you want locked down. It'd also be a good idea to apply some security to the form so it can't be easily unlocked.

A JavaScript Automation tool can be run from a toolbar button. This article is about applying security, but it shows how to create a toolbar button with JavaScript.
http://www.acrobatusers.com/tutorials/2007/10/apply_security_with_js

But there is also a simpler way to run this script, the console window.
http://www.acrobatusers.com/tutorials/2006/javascript_console

Just copy this code, or something like it, into the console:
for(var i=0;i<this.numFields;i++){var cNm = this.getNthFieldName(i);this.getField(cNm).readonly = true;}

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

smithster
Registered: Mar 25 2009
Posts: 4
This is a great tip!
Is there any way to leave the email button out of the "content read only" script? I have a button for form fillers to click and fix the entered fields, but the email button then breaks, although the "hand" still appears to hover over it. Would it be a case of defining each field to "fix" in the script?
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Certainly, all you have to do is test the name before setting it to ReadOnly.
for(var i=0;i<this.numFields;i++){var cNm = this.getNthFieldName(i);if(cNm != "Email")this.getField(cNm).readonly = true;}

But why not put this code into your email button script? Lock before sending. That way you only have one button for the user to push, and you can do validation before sending or locking the form.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

smithster
Registered: Mar 25 2009
Posts: 4
Will this work in Acrobat Reader?
I have added the script to the email button, and tested in Acrobat Reader 7/8/9 - with no luck, errors "operation not permitted"
Any workaround to lock content for end users using only Acrobat Reader?
PeteA
Registered: Mar 16 2009
Posts: 6
I don't know about adding the script to the email button, but I managed to make a form button (I couldn't figure out how to make a button on an existing toolbar (I did get a floating toolbar, which also had a JavaScript warning legend) that does indeed work in Reader to set the read-only attributes of all of the fields.

A button in the form doc itself is perhaps not as elegant as a toolbar button, but you can configure it so that it's viewable only and doesn't print with the document. You can even have the script change the caption from, e.g., "Lock Document" to "Locked" by using the Field Object method buttonSetCaption, e.g.,:

this.getField("Lock").buttonSetCaption("Locked");
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
If you look in the Acrobat JavaScript Reference, at the entry for the "Field.readonly" property, you'll see that in order for this property to be accessable to a form displayed in Reader, the form must have "Form Rights". "Form Rights" are mixed in with the "Rights" that can be applied with Acrobat 8 and 9 Professional.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

smithster
Registered: Mar 25 2009
Posts: 4
Not sure if I understand the JavaScript Reference and Form Rights. any chance of a step by step?

PeteA - any chance you could frward links/script for the toolbar button you mentioned? Does it use standard Acrobat Reader "code", or is it something that the end user needs to install?
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Certain functionality is restricted by Reader. For example, making changes to a form and then saving it to your hard drive. In order to do this action in Reader, the form needs Reader Save Rights. Reader Rights have been around for a long time, and there are several individual Rights. Originally you needed to purchase these Rights from Adobe. But in Acrobat 7, Adobe added the ability to Enable a PDF with Commenting Rights to Acrobat Pro, and then in Acrobat Pro 8 they added the ability to add Save, Form, and Signing Rights.

So, to add these Reader Rights to your form, use the "Advanced > Extend Features in Adobe Reader..." menu item.

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

smithster
Registered: Mar 25 2009
Posts: 4
That's fantastic! Just what I was after, I've also added a "save as" on the SEND EMAIL button to allow end users to keep a local locked copy. Works in Reader!
Thanks very much for your help.
FotoHijinx
Registered: Feb 9 2009
Posts: 8
Hi Thom

I have a form I have created and have used your code:

Code: for(var i=0;i<this.numFields;i++){var cNm = this.getNthFieldName(i);this.getField(cNm).readonly = true;}

And it works great - except that I have a couple of fields that are "required" fields and if they miss entering a required field and hit the email button they can't go back and enter into those fields anymore as they are now locked.

Is there a way around this?

Cheers
Irene
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Use this same loop to test the required fields. If any are not filled out then break out of the loop and warn the user.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

FotoHijinx
Registered: Feb 9 2009
Posts: 8
Hi Thom

Thanks for your quick reply, but I'm afraid I'm not a coder and have no idea how to do what you just said.

Sorry to be a pain but could you provide that code to achieve this.

Cheers
Irene
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Hmm, you're getting into tricky details here. What you really need is a form level validation scirpt that makes sure all is ok before making the fields read only and then sumbitting the form (saving, emailing, or whatever it is thats the final step). The details of creating this kind of script can be many and varied, and depend on the form. So you really have two choices here, either lean enough scripting to do the job or hire someone.

However, there are many threads on this form about just this topic and I and other people have provided script examples. I'd suggest looking around and also attending my eSeminar next week. I'll be providing an example of this as part of the session.

http://www.acrobatusers.com/events/1973/tech-talk-form-data-handling

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

FotoHijinx
Registered: Feb 9 2009
Posts: 8
Thanks Thom - I'll have a look around to see what I can find.

I don't think I'll be able to attend your seminar as I'm in Australia - its bound to be in the middle of the night!!

Cheers
Irene
FotoHijinx
Registered: Feb 9 2009
Posts: 8
Hi Thom

I found some code that I thought might work but something is not right:

var RequiredFields = new Array(5);RequiredFields[0] = "252";RequiredFields[1] = "Name MrMrsMs";RequiredFields[2] = "Street Address";RequiredFields[3] = "Email";RequiredFields[4] = "Phone"; var AlertMsg = new Array(5);AlertMsg[0] = "Please enter the relevant Development Number";AlertMsg[1] = "Please enter your name.";AlertMsg[2] = "Please enter your street address.";AlertMsg[3] = "Please enter your email address.";AlertMsg[4] = "Please enter your phone number."; var bSuccess=Truevar emptyTest=/^\s*$/;var fieldCount=RequiredFields.lengthvar fld=0; for(var i=0;i<fieldCount;i++){fld=this.getField(RequiredFields[i]);if(emptyTest.test(fld.value)){bSuccess=false;app.alert(AlertMsg[i]);fld.setFocus();break;}} var cToAddr = "xx@xxx";var cCCAddr = this.getField("Email").value;var cSubLine = "Application for Statement of Representation"; if(bSuccess = true)this.mailDoc({bUI: true, cTo: cToAddr, cSubject: cSubLine}); for(var i=0;i<this.numFields;i++){var cNm = this.getNthFieldName(i);if(cNm != "Email")this.getField(cNm).readonly = true;}

Any clues?

cheers
Irene
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Pretty good, Congradulations!!

There are only a couple of issues, the line

if(bSuccess = true)

should be:

if(bSuccess == true)

And the looop setting the fields to ReadOnly needs to be inside this "if" statement.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

Juandelacruz
Registered: Oct 23 2009
Posts: 1
hi how does it works?

[url=http://topstretchmarkproducts.com/revitol-stretch-mark-cream-review/]best stretch mark cream[/url]

FotoHijinx
Registered: Feb 9 2009
Posts: 8
Hi Thom

We had a javascript guy at work who looked at it as there were a few issues with the above script - it was missing a few ";" and True should have be true etc.

Anyway, he helped me clean it up and get it working and the correct code is now this (for those following along at home):

var RequiredFields = new Array(5);RequiredFields[0] = "252";RequiredFields[1] = "Name MrMrsMs";RequiredFields[2] = "Street Address";RequiredFields[3] = "Email";RequiredFields[4] = "Phone"; var AlertMsg = new Array(5);AlertMsg[0] = "Please enter the relevant Development Number";AlertMsg[1] = "Please enter your name.";AlertMsg[2] = "Please enter your street address.";AlertMsg[3] = "Please enter your email address.";AlertMsg[4] = "Please enter your phone number."; var bSuccess=true;var emptyTest=/^\s*$/;var fieldCount=RequiredFields.length;var fld=0; for(var i=0;i<fieldCount;i++){fld=this.getField(RequiredFields[i]);if(emptyTest.test(fld.value)){bSuccess=false;app.alert(AlertMsg[i]);fld.setFocus();break;}} var cToAddr = "<span class="spamspan"><span class="u">xx</span> [at] <span class="d">xxx [dot] com</span></span>";var cCCAddr = this.getField("Email").value;var cSubLine = "Application for Statement of Representation"; if(bSuccess == true){ for(var i=0;i<this.numFields;i++){var cNm = this.getNthFieldName(i);this.getField(cNm).readonly = true;} this.mailDoc({bUI: true, cTo: cToAddr, cSubject: cSubLine});  }

So the above code will check to make sure that the required fields are filled in and if they are not it will give an alert message. Once all the required fields are filled in it will then make the document read only and send it in an email.

Cheers
Irene