Copy link to clipboard
Copied
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();
}
}
Copy link to clipboard
Copied
Acrobat Reader can't flatten the pages.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
In Acrobat Reader your script sets only the property readonly.
Copy link to clipboard
Copied
Here's an article that provides the code for hiding a field.
https://acrobatusers.com/tutorials/show_hide_fields
Copy link to clipboard
Copied
It is not so much that I wanted to hide the field, but hide the field if there was no image added.
But I have come up with a simple solution of just adding a "remove field" button for the user to click if there is no image to add, then when they click the save button those buttons are hidden as well. Gets the Job done. My last figure out is how to get the form flattening javascript not to kill URLs.
Backstory
This PDF is a layout that has been created so clients can fill in upcoming webinar information. The overall layout stays the same but the details change. Once filled out and they hit the save button the get a flat PDF they can print. Yes, it is in RGB but for the use, it does not matter.
Copy link to clipboard
Copied
Just to be very clear, you are not flattening the form. Setting the form fields read-only doesn't do that.
There are a number of specific reasons to flatten a form, such as using it with no-Adobe software, or making it (a tiny bit) more difficult to edit; you aren't achieving those things.