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

Javascript function to view attachments

Community Beginner ,
Nov 22, 2017 Nov 22, 2017

I’ve created a button on a customized form in Adobe Acrobat Pro DC to display a list of its attachments. When I click on the button nothing occurs. I get no error msgs, just nothing at all. My Adobe Form does have half a dozen attachments which are visible if I click on the paperclip in the left ribbon. I’d like that same functionality via a customized button, which I have created. I’d appreciate any assistance

The properties of the button I've created are these:

In the button Options I’ve selected the Behavior to Push,

and the State is Up

In the Action option I’ve selected Run a JavaScript. The script is

if (app.viewerVersion < 11)

{ listing_pre_11();

} else {

listing_11(); }

In Document JavaScripts I’ve a script name of listing_file

The script is

function listing_file()

{

// List ANY ATTACHMENTS

var d = event.target.dataObjects;

if (d != null)

for (var i = 0; i < d.length; i++)

{

console.println("Data Object[" + i + "]=" + d.name);

}

}

TOPICS
PDF forms
8.6K
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
1 ACCEPTED SOLUTION
Community Expert ,
Nov 27, 2017 Nov 27, 2017

Hi.

See my previous post: you should replace "event.target.viewState" by "this.viewState".


PDF Acrobatic, InDesigner & Photoshoptographer

View solution in original post

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 ,
Nov 22, 2017 Nov 22, 2017

It doesn't make sense to use event.target.dataObjects, since the target of the Mouse Up event is the button field that has the script attached, and a button cannot have any data objects attached to it. The document can, so you can either use:

var d = dataObjects;

or better yet:

function listing_file(doc) {

     var d = doc.dataObjects;

   // the rest of the function goes here

and call the function like this:

listing_file(this);

I don't see that your Mouse Up script calls the function you created, so that may be part of the problem as well.

Finally, this won't work with file annotations (even though they are displayed in the Attachments panel), but it will work with file attachments. If you want to get file annotations, loop through the annotations in the document and check each one to see if it's a file annotation.

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 Beginner ,
Nov 25, 2017 Nov 25, 2017

Thank you as those corrections almost resolved my issue.

when I click on my button rather than pointing to the pdf attachment list (those displayed by going to the paperclip in the left ribbon) it takes me to one of my directories where this pdf form is stored.  Can you advise how to point to the attachment list?

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 ,
Nov 23, 2017 Nov 23, 2017

You may just display the attachment pane, using this undocumented function:

this.viewState = {overViewMode:7};


PDF Acrobatic, InDesigner & Photoshoptographer
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 Beginner ,
Nov 26, 2017 Nov 26, 2017

I'd like to use your solution.  , but so far no progress.

I have created a button, and in the action tab selected "mouse up", and "run a javascript."  the edited javascript is what you have provided ~

event.target.viewState = {overViewMode:7};

i get no results.  there are several attachments to the form.

Am I missing something in what you have provided? are there additional steps or commands?

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 ,
Nov 27, 2017 Nov 27, 2017

Hi.

See my previous post: you should replace "event.target.viewState" by "this.viewState".


PDF Acrobatic, InDesigner & Photoshoptographer
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 Beginner ,
Nov 27, 2017 Nov 27, 2017

Thanks very much.  Making that change did result in exactly what I was looking for.  Now there is a new flaw:  When I push the button i get the hoped for results.  But if i close the form and re-open it and click the button i get no results.  I have checked the javascript and it has not changed.  any idea why?

another question. Do I need to place the javascript in the Document JavaScripts pane also, or will  placing it simply in the Button Action box suffice?

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 Beginner ,
Nov 27, 2017 Nov 27, 2017

However when the button does not function as mentioned previously, if i click on the paperclip in the left ribbon and then click on the button it does work.  very strange

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 ,
Nov 27, 2017 Nov 27, 2017

"Undocumented" mean that you use it at your own risk, and that surprises are always possible…


PDF Acrobatic, InDesigner & Photoshoptographer
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 Beginner ,
Nov 27, 2017 Nov 27, 2017
LATEST

anyhow very much appreciated your very efficient solution

Sent from (https://protonmail.com), Swiss-based encrypted email.

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