Copy link to clipboard
Copied
Hi
I have a button on my test document that makes all fields read only when the salesrep has finished editing.
for (var i = 0; i < this.numFields; i++) {
var fname = this.getNthFieldName(i);
this.getField(fname).readonly = true; // makes all fields readonly
}
I​t works perfectly, but I've realised that when I add the rest of the pages back into the document, there are fillable fields on pages 2 and 3 that a customer might need to complete once they've received the document.
So, is it possible to make only page 1 read only and leave pages 2 and 3 editable?
Thank you
Sure. You can use this code to do it:
for (var i = 0; i < this.numFields; i++) {
var fname = this.getNthFieldName(i);
var f = this.getField(fname);
if (f.page==0) f.readonly = true; // makes only fields on page 1 readonly
}
Copy link to clipboard
Copied
Sure. You can use this code to do it:
for (var i = 0; i < this.numFields; i++) {
var fname = this.getNthFieldName(i);
var f = this.getField(fname);
if (f.page==0) f.readonly = true; // makes only fields on page 1 readonly
}
Copy link to clipboard
Copied
I thought that had worked, but it seems to have left all the radio buttons on page 1 editible?
Copy link to clipboard
Copied
Yeah, fields with more than one "widget" are a bit more tricky... Try this:
if ((typeof f.page=="number" && f.page==0) || (typeof f.page=="object" && f.page.indexOf(0)!=-1)) f.readonly = true;
Copy link to clipboard
Copied
That's perfect - thank you!
Copy link to clipboard
Copied
If you don't need the information on the first page to remain in form fields, you can also flatten that page using the Doc.flattenPages() command: Acrobat DC SDK Documentation - Doc.flattenPages()
This will however only work if you have Adobe Acrobat (and not in the free Reader). The JavaScript code to flatten just the first line is this:
this.flattenPages(0);
Copy link to clipboard
Copied
Thanks for this Karl, I will keep a note of the code a I'm sure it will come into use soon