Skip to main content
Utopia Creative Group
Participating Frequently
March 12, 2019
Question

Remove the "add image" icon on flatten save javascript if no image selected in Acrobat Reader

  • March 12, 2019
  • 1 reply
  • 1014 views

I have a document that allows for someone to add a headshot next to a description using the built-in "add image button" but in some cases, they may not have a headshot to add. We have added a save button that flattens the PDF and removes said button but would also like it to remove the add image icon if there is no image. This is not an issue in Acrobat Pro as I guess it understands what that icon is and removes it if no image has been added but in Reader where this is meant to be used the icon stays on the page once flattened.

My "Save Document" button is set up as such.

on Mouse Down:

- Hide Save Document Button

- Run Flatten Javascript (see below)

- Execute Menu item... File>Save as

The Javascript:

flattenFields()

function flattenFields(){

  if (app.viewerType=="Reader"){

      for (var i=0 ; i<this.numFields ; i++) {

          var f = this.getField(this.getNthFieldName(i)) ;

          if (f==null) continue;

          f.readonly = true

      }

    } else {

       this.flattenPages();

    }

}

This topic has been closed for replies.

1 reply

Bernd Alheit
Community Expert
Community Expert
March 12, 2019

Acrobat Reader can't flatten the pages.

Utopia Creative Group
Participating Frequently
March 12, 2019

The script seems to work, at least to the point in that flatten means that the forms cannot be edited after it is run which is what we want.

My question was about a way to remove the icon when or after the script has run.

try67
Community Expert
Community Expert
March 12, 2019

The icon of an image can only be removed using a script if you:

- redact the field

- delete it

- hide it

- or copy the icon from an empty button field to it

The last three are not possible if you flatten the fields, though.