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

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

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

TOPICS
Acrobat SDK and JavaScript , Windows

Views

526

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

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

}

Votes

Translate

Translate
Community Expert ,
Oct 03, 2018 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

}

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

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

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

Copy link to clipboard

Copied

That's perfect - 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 ,
Oct 03, 2018 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);

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

Copy link to clipboard

Copied

LATEST

Thanks for this Karl, I will keep a note of the code a I'm sure it will come into use soon

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