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

how to create a delete page function that works in Reader

Community Beginner ,
Aug 10, 2023 Aug 10, 2023

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.

TOPICS
Create PDFs , Edit and convert PDFs , General troubleshooting , How to , JavaScript , PDF , PDF forms , Security digital signatures and esignatures
4.5K
Translate
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
1 ACCEPTED SOLUTION
Community Expert ,
Aug 11, 2023 Aug 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.

View solution in original post

Translate
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 ,
Aug 11, 2023 Aug 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.

Translate
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 Beginner ,
Aug 11, 2023 Aug 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.

Translate
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 Beginner ,
Aug 11, 2023 Aug 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 ?

Translate
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 Beginner ,
Aug 11, 2023 Aug 11, 2023

Another follow-up: I could not save the form until I e-signed. Is there a way to allow saving prior to e-signing? 

Translate
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 ,
Aug 11, 2023 Aug 11, 2023

- Specify nPage as -1.

- Saving should be possible, regardless of signing. What happens when you try to save the file?

Translate
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 Beginner ,
Aug 11, 2023 Aug 11, 2023

A dialog box pops up saying "The document could not be saved. This file cannot be found."

Translate
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
New Here ,
Jan 25, 2024 Jan 25, 2024

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!!

Translate
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 ,
Jan 25, 2024 Jan 25, 2024
LATEST

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.

Translate
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
Advocate ,
Aug 11, 2023 Aug 11, 2023

deletePages is specified as

MikelKlink_0-1691743451551.pngexpand image

(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.

Translate
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 ,
Aug 11, 2023 Aug 11, 2023

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

Translate
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
Advocate ,
Aug 11, 2023 Aug 11, 2023

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

Translate
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 ,
Aug 12, 2023 Aug 12, 2023

Unfortunately, no. Adobe often makes changes to the capabilities of the application without updating the JS Documentation.

Translate
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