Skip to main content
davidr41478633
Participating Frequently
May 25, 2018
Answered

Can you make a javascript run to delete all unfilled photo fields and fields with certain values and then delete the empty pages?

  • May 25, 2018
  • 2 replies
  • 644 views

I am working to build a document for my company that we can use to include photos. Each photo document will have a different number of pictures and i would like an easy way for others to be able to delete unused photo fields and unused caption fields below the photos. After the fields are deleted I was hoping that there would also be a way to delete pages that don't have any photo fields present. I am very new to coding javascript, but i thought that i would give this a shot.

Here is the document that i have started. Any help is appreciated. thanks

https://drive.google.com/open?id=1vJ10Zv5QsVewcx0fSdvBcYKEw_uMheUR

Thanks

This topic has been closed for replies.
Correct answer Joel Geraci

You might want to rethink your solution. Rather than have as many photo pages as you may ever need and then delete the ones that you don't... which will be hard to figure out... use page templates to spawn a new photo page only when one is needed. Much easier to do.

2 replies

Joel Geraci
Community Expert
Joel GeraciCommunity ExpertCorrect answer
Community Expert
May 25, 2018

You might want to rethink your solution. Rather than have as many photo pages as you may ever need and then delete the ones that you don't... which will be hard to figure out... use page templates to spawn a new photo page only when one is needed. Much easier to do.

davidr41478633
Participating Frequently
May 25, 2018

Thanks, after rethinking the solution and testing out spawning a new page. i think that this is a better solution to my problem.

try67
Community Expert
Community Expert
May 25, 2018

Is this file going to be used in Acrobat or in Reader, or in another application?

There's no point in deleting fields and then deleting the pages they're on. You can just delete the pages directly...

davidr41478633
Participating Frequently
May 25, 2018

This will be used in acrobat.

That makes since i just want to make sure that if there are 7 total photos that page 2 is not completely deleted, only the 5 unused photo fields and caption fields.

thanks for the help

try67
Community Expert
Community Expert
May 25, 2018

Deleting a field is easy. Finding out whether a button field has an image or not is not so easy...

To do the former just use the removeField method, like this:

this.removeField("Button1");