Remove the "add image" icon on flatten save javascript if no image selected in Acrobat Reader
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();
}
}
