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

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

Participant ,
Feb 13, 2024 Feb 13, 2024

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. 

TOPICS
JavaScript , PDF , PDF forms
2.4K
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 ,
Feb 13, 2024 Feb 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);

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 ,
Feb 13, 2024 Feb 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);

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 ,
Feb 13, 2024 Feb 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!

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 ,
Feb 13, 2024 Feb 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).

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
Participant ,
Feb 14, 2024 Feb 14, 2024

Hi Nesa,

 

Thanks for your help. I have added the code to a Combo Box in the calculate script custom calculation area.

 

var v = this.getField("Combo Box 1").value; if (v === “two”) { var f = this.getField("Text 2").page; this.deletePages(f); } if (v=== "three"){ var g = this.getField("Text 3").page; this.deletePages(g); }

But it doesn't seem to be working.

Have I done something wrong

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

There are errors in your code. Check the JS Console. You must always use straight quotes, not curly ones.

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
Participant ,
Feb 14, 2024 Feb 14, 2024

Many thanks, now working

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
Explorer ,
Feb 27, 2024 Feb 27, 2024

Are you able to share how you got this working? I'm working on a similar issue and keep getting errors.

 

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
Participant ,
Feb 28, 2024 Feb 28, 2024
LATEST

It started working after I changed the typographers qupotes to regular quotes.

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