Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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 ?
Copy link to clipboard
Copied
Another follow-up: I could not save the form until I e-signed. Is there a way to allow saving prior to e-signing?
Copy link to clipboard
Copied
- Specify nPage as -1.
- Saving should be possible, regardless of signing. What happens when you try to save the file?
Copy link to clipboard
Copied
A dialog box pops up saying "The document could not be saved. This file cannot be found."
Copy link to clipboard
Copied
Hi! And what would the script be to but on the botton that delets that page? I tried with this.deletePages(this.pageNum) but it deleted that page template. Can that be? I mean it worked, it deleted the page, but when I went to my templates it deleted there too...
I have a form that the first page, always visible, has 2 buttons. Depending on which one you choose, a page template is spawn. The thing is that every time you click there is a new page and I want people to be able to delete the extra ones or to only be able to spawn one page of that given template, as they won't need more.
Hope I'm explaining myself, I'm VERY new at this and it is difficult to follow.
Thank you!!
Copy link to clipboard
Copied
You have to first hide the Template page, then spawn a new page from it, and then you will be able to delete that page without affecting the original Template.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
The latter is not relevant if the file is used in Reader DC.
Copy link to clipboard
Copied
Do you know whether there is a publicly available JS API specification including updates like this?
Copy link to clipboard
Copied
Unfortunately, no. Adobe often makes changes to the capabilities of the application without updating the JS Documentation.

