Skip to main content
New Participant
August 10, 2023
Answered

how to create a delete page function that works in Reader

  • August 10, 2023
  • 2 replies
  • 5441 views

Greetings,

 

I apologize in advance for my post being very basic -- I am a novice when it comes to using Acrobat Pro.

 

I've been tasked by my supervisor with creating a 3-page PDF that includes an instruction page on page 1 and a delete button that will remove said instruction page. The remaining two pages are a fillable form. I am using the following script for my delete function:

 

this.deletePages(this.pageNum)

 

I am working on a Macbook Air using the latest version of Acrobat Pro. The button works for me when I preview the PDF in Acrobat Pro. However, when I test out the delete button in the latest version of Reader on my personal Macbook Air, nothing happens and I get the following error message in the Javascript debugger:

 

RaiseError: This operation is not permitted.

Doc.deletePages:1:Field Button3:Mouse Up

===> This operation is not permitted.

 

In Acrobat Pro, I've verified that I have no document restrictions enabled (all say "Allowed"). I also made sure that "No Security" is selected for the Security Method and that "All versions of Acrobat" is showing next to "Can be Opened by:" in the Document Properties > Document Security > Security Method menu. However, in Reader the document restrictions show that Document Assembly and Page Extraction are not allowed. I have no idea how this is happening or if this is the root cause of the error, but I am at a loss and could really use some help in how to correct this problem. 

 

Additionally, I would like to include a digital signature field but have omitted one for now as I troubleshoot the delete button problem. I worry that the e-signature might cause further issues with permissions by interacting with the delete button's properties.

 

I've attached a skeleton version of the form. Thank you in advance for your time and help.

This topic has been closed for replies.
Correct answer try67

Pages can only be deleted in Reader if they were spawned from a Template page.

To do that you would need to:

- Convert your pages to Templates.

- Hide them.

- Spawn a page from them.

- Add a button with a script to delete them.

Of course, you can't delete all pages in the files. There must always be at least one (visible) page.

2 replies

MikelKlink
Participating Frequently
August 11, 2023

deletePages is specified as

(https://opensource.adobe.com/dc-acrobat-sdk-docs/acrobatsdk/pdfs/acrobatsdk_jsapiref.pdf)

So first of all, to be able to delete a page in Acrobat Reader it must be a spawned page template as @try67 already explained. See their answer for an idea how to make the page a spawned template.

Furthermore, the 'F' in the quick bar and the text in the body of the specification indicate that form usage rights need to be enabled in the PDF.

try67
Community Expert
August 11, 2023

The latter is not relevant if the file is used in Reader DC.

MikelKlink
Participating Frequently
August 12, 2023

Do you know whether there is a publicly available JS API specification including updates like this?

try67
try67Correct answer
Community Expert
August 11, 2023

Pages can only be deleted in Reader if they were spawned from a Template page.

To do that you would need to:

- Convert your pages to Templates.

- Hide them.

- Spawn a page from them.

- Add a button with a script to delete them.

Of course, you can't delete all pages in the files. There must always be at least one (visible) page.

Jay.TeeAuthor
New Participant
August 11, 2023

Thank you, this overall process worked for me. I'm posting my process below in case it's helpful for any other novices.

 

I tried using the following code to spawn that's in the SDK linked below—

 

var a = this.templates; for (i = 0; i < a.length; i++) a[i].spawn(this.numPages, false, false);

 

But I kept getting the following error: TypeError: a is null. Here is the code I ended up using that I found elsewhere online—

 

var a = this.getTemplate("newpage");
a.spawn({nPage: pageNum + 1, bRename: true, bOverlay: false});

 

I switched out new page for the name of my template page and got it to work. Now I can't seem to figure out how to make the template page appear as the first page.

Jay.TeeAuthor
New Participant
August 11, 2023

Follow-up: to get the spawned page to appear first, the # value in the second line needs to be 0.

 

Now I run into another problem: I can't save the form once it's filled out. Could you please let me know how to correct this @try67 ?