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

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

Explorer ,
Mar 12, 2019 Mar 12, 2019

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();

    }

}

TOPICS
Acrobat SDK and JavaScript
1.0K
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 ,
Mar 12, 2019 Mar 12, 2019

Acrobat Reader can't flatten the pages.

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 ,
Mar 12, 2019 Mar 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.

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 ,
Mar 12, 2019 Mar 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.

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 ,
Mar 12, 2019 Mar 12, 2019

In Acrobat Reader your script sets only the property readonly.

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 ,
Mar 12, 2019 Mar 12, 2019

Here's an article that provides the code for hiding a field.

https://acrobatusers.com/tutorials/show_hide_fields

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 ,
Mar 12, 2019 Mar 12, 2019

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.

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
LEGEND ,
Mar 12, 2019 Mar 12, 2019
LATEST

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.

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