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

Deleting multiple spawned pages - Adobe Pro DC

New Here ,
Apr 12, 2021 Apr 12, 2021

Copy link to clipboard

Copied

Hi everyone. 

I have created an application form (pages 1-3) which the applicant fills out. I have a hidden button which spawns a permit (pages 4-7)  - all four pages appear together. Re-clicking the button deletes pages 4-7, but it deletes one page at a time i.e. requires four clicks. Is there a way to delete pages 4-7 with one click? Using Adobe Acrobat DC, Windows 10.

Here is the script I'm using:

 

// This script is activated by "Mouse-Up" on a hidden button

// Get a reference to the template


var t1 = getTemplate("Pg4");
var t2 = getTemplate ("Pg5");
var t3 = getTemplate ("Pg6");
var t4 = getTemplate ("Pg7");
var spwndel = this.numPages;
// Create a new page, but only if there's currently only three pages in this document;

if (numPages == 3)
{


t1.spawn({nPage: numPages, bRename: true, bOverlay: false});
t2.spawn({nPage: numPages, bRename: true, bOverlay: false});
t3.spawn({nPage: numPages, bRename: true, bOverlay: false});
t4.spawn({nPage: numPages, bRename: true, bOverlay: false});
// this piece works - it adds the correct pages
} else
{

// this piece deletes pagespages 4, 5, 6 and 7 , but have to click 4 times

if(numPages>3)
{
deletePages(3);
deletePages(4);
deletePages(5);
deletePages(6);

}

}

 

Any help gratefully received!

 

TOPICS
How to

Views

710

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 , Apr 12, 2021 Apr 12, 2021

The action you are seeing is a bit odd. If you follow the logic, this code is expected to fail, just not in the way you have described.  For example, when page 3 is deleted the document is shortened by one page, so there is no page 6. However, there is a page 4, so I would expect two pages to be deleted before the failure. 

Have you looked in the console window to see what errors are reported, because there are errors. 

 

Here is a "dressed" (i.e. neater) version of your code.

if (this.numPages 
...

Votes

Translate

Translate
Community Expert ,
Apr 12, 2021 Apr 12, 2021

Copy link to clipboard

Copied

Let me move this to the Acrobat forum for you, which is the appropriate forum for your question.

The Using the Community forum is for help in using the Adobe Support Community forums, not for help with specific programs. Product questions should be posted in the associated product community.

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 ,
Apr 12, 2021 Apr 12, 2021

Copy link to clipboard

Copied

Try this:

 

this.deletePages(3,6);

 

You are also missing an explicit document object reference from the document function calls. It is a good practice to include "this".   🙂  pun intended.

 

Here's the reference entry for the deletePages function 

https://help.adobe.com/en_US/acrobat/acrobat_dc_sdk/2015/HTMLHelp/#t=Acro12_MasterBook%2FJS_API_Acro...

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 ,
Apr 12, 2021 Apr 12, 2021

Copy link to clipboard

Copied

The action you are seeing is a bit odd. If you follow the logic, this code is expected to fail, just not in the way you have described.  For example, when page 3 is deleted the document is shortened by one page, so there is no page 6. However, there is a page 4, so I would expect two pages to be deleted before the failure. 

Have you looked in the console window to see what errors are reported, because there are errors. 

 

Here is a "dressed" (i.e. neater) version of your code.

if (this.numPages == 3)
{
    this.getTemplate("Pg4").spawn(this.numPages,false, false);
    this.getTemplate("Pg5").spawn(this.numPages,false, false);
    this.getTemplate("Pg6").spawn(this.numPages,false, false);
    this.getTemplate("Pg7").spawn(this.numPages,false, false);
} else if(numPages>3)
{
    this.deletePages(3,6);
}

 

Note that the renaming argument is false. There is no need to rename fields if the template will only ever be spawned once. 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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
New Here ,
Apr 12, 2021 Apr 12, 2021

Copy link to clipboard

Copied

LATEST

Thom - thank you so much! Worked like a charm. Here is the full working script:

// Get a reference to the template

var t1 = getTemplate("Pg4");
var t2 = getTemplate ("Pg5");
var t3 = getTemplate ("Pg6");
var t4 = getTemplate ("Pg7");
var spwndel = this.numPages;
// Create a new page, but only if there's currently only three pages in this document;

if (numPages == 3)
{


t1.spawn({nPage: numPages, bRename: true, bOverlay: false});
t2.spawn({nPage: numPages, bRename: true, bOverlay: false});
t3.spawn({nPage: numPages, bRename: true, bOverlay: false});
t4.spawn({nPage: numPages, bRename: true, bOverlay: false});
// this piece works - it adds the correct pages
} else

{
if(numPages>3)
this.deletePages(3, 6);
}

 

Once again, many thanks!

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