Skip to main content
Inspiring
September 9, 2021
Answered

Can I use this.flattenPages(); to just flatten the first page of a document or a certain range?

  • September 9, 2021
  • 1 reply
  • 9409 views

Hi Everyone, 

 

I created a form for clients to fill. This form has 2 pages. The first page I would like to lock or flatten the data submitted once I am done my review and stamp it and not have the second page locked so that others can complete the  second page of the form and sign off. 

 

I have Acrobat DC Pro. 

 

Can I use the java scipt  "this.flattenPages(); " and have it only flatten the first page? Is there addition code I can use to limit the range of flatten?

 

I cannot use any add-ons and I am restricted to what I have for software. 

  

Thanks in advance. 

This topic has been closed for replies.
Correct answer Ryan5E98

If you want to flatten just one page (lets say page 2) use like this:

this.flattenPages(1);

if you want to flatten range of pages lets say 1-3:

this.flattenPages(0,2);


Thank you this worked. 

 

To flatten page 1 I used: this.flattenPages(0);

 

 

1 reply

Thom Parker
Community Expert
Community Expert
September 9, 2021

Yes, the "flattenPages()" function has inputs for  start page and end page. So you can flatten any page range you want.

 

Here's the reference entry:

https://opensource.adobe.com/dc-acrobat-sdk-docs/acrobatsdk/html2015/index.html#t=Acro12_MasterBook%2FJS_API_AcroJS%2FDoc_methods.htm%23TOC_flattenPagesbc-34&rhtocid=_6_1_8_23_1_33

 

 

However, this function will only work in Acrobat Pro. It will not work in Acrobat Reader, or pretty much any other PDF viewer. I would suggest that you make the fields ReadOnly instead.  

 

Another alternative is to use the Adobe Sign process, which allows fine control over the form distribution process, but unfortunately is pretty weak on the actual form fields and doesn't allow any scripting. 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Ryan5E98Author
Inspiring
September 10, 2021

this.flattenPages({nStart: 0, nEnd: 0});

this.flattenPages({nStart: 0, nEnd: 1});

this.flattenPages({nStart: 1, nEnd: 1});

 

All result in flattening every page, any suggestions?

try67
Community Expert
Community Expert
September 10, 2021

That should not be the case. Can you share the actual file with us (before you flattened it, of course)?