Skip to main content
Inspiring
February 13, 2024
Answered

Javascript to delete pdf pages using a form field as page marker

  • February 13, 2024
  • 1 reply
  • 2288 views

Hi there,

 

I would like to know if anyone has found javascript that would find a specific form text field name and then delete the page it is on?

 

I am working on a form that new pages will be added if the client uses a dropdown to select number of accounts and the template spawns from that. But I would like to give the client the opportunity to change the number of spawn pages if they have got it wrong. Complete novice to this. I did the original with show hide javascript but the client has asked for the pages to delete. 

This topic has been closed for replies.
Correct answer Nesa Nurani

You can use 'page' property to find page number of a specific field, for example let's say you want to delete page where "Text1" field is located:
var f = this.getField("Text1").page;
this.deletePages(f);

1 reply

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
February 13, 2024

You can use 'page' property to find page number of a specific field, for example let's say you want to delete page where "Text1" field is located:
var f = this.getField("Text1").page;
this.deletePages(f);

try67
Community Expert
Community Expert
February 13, 2024

Just be aware this will only work if there's only one copy of the field. If there are more copies of it, even on the same page, the page property will return an array, not a number!

try67
Community Expert
Community Expert
February 13, 2024

PS. Also, you need to check if the page number is not -1, or you could accidentally delete the Template page (or it will produce an error).