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

Script help required to get the pages that are actually spawned to delete.

Explorer ,
Feb 16, 2024 Feb 16, 2024

Copy link to clipboard

Copied

Hi there,

 

I have a script that needs to run each time to delete the spawned pages in the pdf document. 

 

Unfortunately, it stops if any of the pages aren't spawned. Is there anyway to get the script to run and ignore the pages that aren't spawned. Basic I want to reset the spawned pages before more are spawned through the javascipt. 

 

var f = this.getField("Page text 5.1").page; this.deletePages(f);
var g = this.getField("Page text 6.1").page; this.deletePages(g);
var h = this.getField("Page text 7.1").page; this.deletePages(h);
var j = this.getField("Section4-5.1").page; this.deletePages(j);
var k = this.getField("Section4-6.1").page; this.deletePages(k);
var l = this.getField("Section4-7.1").page; this.deletePages(l);
var m = this.getField("Section4-8.1").page; this.deletePages(m);

 

Any help would be greatly appreciated. 

 

Steve

TOPICS
JavaScript , Modern Acrobat , PDF

Views

73

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 ,
Feb 16, 2024 Feb 16, 2024

Copy link to clipboard

Copied

Hi,

 

you could wrap them in try{} catch(){} blocks and this way you can return an error, or at least handle when one has gone wrong, if you want them all to continue the I would recommend something like

 

```

try {

    var f = this.getField("Page text 5.1").page;

   this.deletePages(f);

} catch (e) {

console.println ( "ERROR occoured at f " + e);

}

```

if you create a try...catch for each it will tell you which one failed, but it should also allow the others to succeed.

 

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 ,
Feb 16, 2024 Feb 16, 2024

Copy link to clipboard

Copied

LATEST

So what you need to do is to test for the existance of a template before trying to delete it.

 

The page number for a field on a template that is not spawned is -1.

However, it's not that easy because the "page" property is only a single number if there is only one instance of it. As soon as the page is spawned there are potentially two instances on the form. One on the hidden template and one on the spawned template.   So the "page" property is an an array of page numbers. You need to write a function to search the page array for a positive number. 

Of course this only works if the template is spawned without renaming fields. If the fields are renamed, then you'll need to search all field names for the one with the matching postfix. 

 

 

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