Is it possible to ONLY make one page read-only in a document?

Oct 03, 2018

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

}

TOPICS
Acrobat SDK and JavaScript, Windows

Views

124

Likes

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

Is it possible to ONLY make one page read-only in a document?

Oct 03, 2018

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

}

TOPICS
Acrobat SDK and JavaScript, Windows

Views

125

Likes

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
Oct 03, 2018 0
Oct 03, 2018

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

}

Likes

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
Reply
Loading...
Oct 03, 2018 2
Oct 03, 2018

Copy link to clipboard

Copied

I thought that had worked, but it seems to have left all the radio buttons on page 1 editible?

Likes

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
Reply
Loading...
Oct 03, 2018 0
Oct 03, 2018

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;

Likes

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
Reply
Loading...
Oct 03, 2018 1
Oct 03, 2018

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

Likes

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
Reply
Loading...
Oct 03, 2018 0
Oct 03, 2018

Copy link to clipboard

Copied

That's perfect - thank you!

Likes

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
Reply
Loading...
Oct 03, 2018 0
jlehane LATEST
Oct 03, 2018

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

Likes

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
Reply
Loading...
Oct 03, 2018 0