event.target.buttonImportIcon();

New Here ,
Sep 16, 2016

Copy link to clipboard

Copied

First, let me say that I know just enough to be dangerous...so please be kind.

FYI - I have Acrobat, full paid, most up to date version.

I have created a form and as part of that form I have multiple boxes for inserting photos. I'm using the script event.target.buttonImportIcon(); to insert the photos. I'm aware that in the free version, only PDFs may be inserted. However, I do have the full version. When the box pops up for me to find the photo to insert, it defaults to only showing PDFs. I can change that to JPGs and browse, but this is cumbersome because each time I complete this form I need to attach 12-18 photos for documentation.

My question is, Is there a way to have the box that pops up set to view JPGs? Or at least to view all file extensions? I know this doesn't seem like a huge deal, but I do 3-5 of these forms per day, with 12-18 photos each, so it would be nice not to have to change the file type I'm searching for each time.

Thanks so much for your help!

Adobe Community Professional
Correct answer by George_Johnson | Adobe Community Professional

Someone requested more info, so here's a more complete script that can be placed in a folder-level JavaScript file:

var ASGJ_buttonImportIconAll = app.trustedFunction(function (doc, f_name) {

    // Get a reference to the specified field

    var f = doc.getField(f_name);

    // If the specified field does not exist...

    if (!f) {

        app.beginPriv();

        app.alert({

            cMsg: "The specified field [" + f_name + "] does not exist.",

            nIcon: 0,  // Error icon

            nType: 0,  // OK

            cTitle: "Field does not exist"

        });

        app.endPriv();

        return;

    }

    // If the specified field is not a button...

    if (f.type !== "button") {

        app.beginPriv();

        app.alert({

            cMsg: "The specified field [" + f_name + "] is not a button.\r\rField type: " + f.type + "\r\rCannot import icon.",

            nIcon: 0,  // Error icon

            nType: 0,  // OK

            cTitle: "Field is not a button"

        });

        app.endPriv();

        return;

    }

    // If the button layout is label only...

    if (f.buttonPosition === position.textOnly) {

        app.beginPriv();

        app.alert({

            cMsg: "The specified button [" + f_name + "] has a Text-only layout.\r\rCannot import icon.",

            nIcon: 0,  // Error icon

            nType: 0,  // OK

            cTitle: "Button layout is text-only"

        });

        app.endPriv();

        return;

    }

    // Prompt user to select a file to use as the source for the button icon

    app.beginPriv();

    var oFilespec = app.browseForDoc({

        cFileFilter: 2,

        cWindowTitle: "Select an image"

    });

    app.endPriv();

    // Deal with the selected file

    if (typeof oFilespec !== "undefined") {

        // Attempt to use the selected file as the source of the button icon

        app.beginPriv();

        var nReturn = f.buttonImportIcon({

            cPath: oFilespec.cPath

        });

        app.endPriv();

        switch (nReturn) {

        case -1 :

            app.beginPriv();

            app.alert({

                cMsg: "The selected file: " + oFilespec.cPath + "\r\rcould not be opened." ,

                nIcon: 0,  // Error icon

                nType: 0,  // OK

                cTitle: "Cannot open selected file"

            });

            app.endPriv();

            break;

        case -2 :

            app.beginPriv();

            app.alert({

                cMsg: "The selected page is invalid.\r\rCannot import icon.",

                nIcon: 0,  // Error icon

                nType: 0,  // OK

                cTitle: "Selected page invalid"

            });

            app.endPriv();

            break;

        default :

            // Import was successful or user canceled

            // so there's nothing to do

        }

    }

});

The function can be called like this in the Mouse Up event of a button:

ASGJ_buttonImportIconAll(this, event.target.name);

TOPICS
Acrobat SDK and JavaScript, PDF forms, Windows

Views

2.6K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

event.target.buttonImportIcon();

New Here ,
Sep 16, 2016

Copy link to clipboard

Copied

First, let me say that I know just enough to be dangerous...so please be kind.

FYI - I have Acrobat, full paid, most up to date version.

I have created a form and as part of that form I have multiple boxes for inserting photos. I'm using the script event.target.buttonImportIcon(); to insert the photos. I'm aware that in the free version, only PDFs may be inserted. However, I do have the full version. When the box pops up for me to find the photo to insert, it defaults to only showing PDFs. I can change that to JPGs and browse, but this is cumbersome because each time I complete this form I need to attach 12-18 photos for documentation.

My question is, Is there a way to have the box that pops up set to view JPGs? Or at least to view all file extensions? I know this doesn't seem like a huge deal, but I do 3-5 of these forms per day, with 12-18 photos each, so it would be nice not to have to change the file type I'm searching for each time.

Thanks so much for your help!

Adobe Community Professional
Correct answer by George_Johnson | Adobe Community Professional

Someone requested more info, so here's a more complete script that can be placed in a folder-level JavaScript file:

var ASGJ_buttonImportIconAll = app.trustedFunction(function (doc, f_name) {

    // Get a reference to the specified field

    var f = doc.getField(f_name);

    // If the specified field does not exist...

    if (!f) {

        app.beginPriv();

        app.alert({

            cMsg: "The specified field [" + f_name + "] does not exist.",

            nIcon: 0,  // Error icon

            nType: 0,  // OK

            cTitle: "Field does not exist"

        });

        app.endPriv();

        return;

    }

    // If the specified field is not a button...

    if (f.type !== "button") {

        app.beginPriv();

        app.alert({

            cMsg: "The specified field [" + f_name + "] is not a button.\r\rField type: " + f.type + "\r\rCannot import icon.",

            nIcon: 0,  // Error icon

            nType: 0,  // OK

            cTitle: "Field is not a button"

        });

        app.endPriv();

        return;

    }

    // If the button layout is label only...

    if (f.buttonPosition === position.textOnly) {

        app.beginPriv();

        app.alert({

            cMsg: "The specified button [" + f_name + "] has a Text-only layout.\r\rCannot import icon.",

            nIcon: 0,  // Error icon

            nType: 0,  // OK

            cTitle: "Button layout is text-only"

        });

        app.endPriv();

        return;

    }

    // Prompt user to select a file to use as the source for the button icon

    app.beginPriv();

    var oFilespec = app.browseForDoc({

        cFileFilter: 2,

        cWindowTitle: "Select an image"

    });

    app.endPriv();

    // Deal with the selected file

    if (typeof oFilespec !== "undefined") {

        // Attempt to use the selected file as the source of the button icon

        app.beginPriv();

        var nReturn = f.buttonImportIcon({

            cPath: oFilespec.cPath

        });

        app.endPriv();

        switch (nReturn) {

        case -1 :

            app.beginPriv();

            app.alert({

                cMsg: "The selected file: " + oFilespec.cPath + "\r\rcould not be opened." ,

                nIcon: 0,  // Error icon

                nType: 0,  // OK

                cTitle: "Cannot open selected file"

            });

            app.endPriv();

            break;

        case -2 :

            app.beginPriv();

            app.alert({

                cMsg: "The selected page is invalid.\r\rCannot import icon.",

                nIcon: 0,  // Error icon

                nType: 0,  // OK

                cTitle: "Selected page invalid"

            });

            app.endPriv();

            break;

        default :

            // Import was successful or user canceled

            // so there's nothing to do

        }

    }

});

The function can be called like this in the Mouse Up event of a button:

ASGJ_buttonImportIconAll(this, event.target.name);

TOPICS
Acrobat SDK and JavaScript, PDF forms, Windows

Views

2.6K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Sep 16, 2016 0
Most Valuable Participant ,
Sep 16, 2016

Copy link to clipboard

Copied

Sorry, it's not possible to change it. You can submit a feature request here: Feature Request/Bug Report Form

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 16, 2016 0
New Here ,
Sep 16, 2016

Copy link to clipboard

Copied

Okay, thanks for the quick response!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 16, 2016 0
Adobe Community Professional ,
Sep 16, 2016

Copy link to clipboard

Copied

It is possible to show all files if you can place the code in a folder-level JavaScript file on each user's system or certify the document and have your users trust it for privileged JavaScript. The code can be something like:

// Prompt the user to select a file [All files (*.*)]

var oFilespec = app.browseForDoc({cFileFilter: 2});

// If the user selected a file, attempt to use it as the button's icon

if (typeof oFilespec !== "undefined") {

    getField("Button1").buttonImportIcon({cPath: oFilespec.cPath});

}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 16, 2016 0
Adobe Community Professional ,
Sep 17, 2016

Copy link to clipboard

Copied

Someone requested more info, so here's a more complete script that can be placed in a folder-level JavaScript file:

var ASGJ_buttonImportIconAll = app.trustedFunction(function (doc, f_name) {

    // Get a reference to the specified field

    var f = doc.getField(f_name);

    // If the specified field does not exist...

    if (!f) {

        app.beginPriv();

        app.alert({

            cMsg: "The specified field [" + f_name + "] does not exist.",

            nIcon: 0,  // Error icon

            nType: 0,  // OK

            cTitle: "Field does not exist"

        });

        app.endPriv();

        return;

    }

    // If the specified field is not a button...

    if (f.type !== "button") {

        app.beginPriv();

        app.alert({

            cMsg: "The specified field [" + f_name + "] is not a button.\r\rField type: " + f.type + "\r\rCannot import icon.",

            nIcon: 0,  // Error icon

            nType: 0,  // OK

            cTitle: "Field is not a button"

        });

        app.endPriv();

        return;

    }

    // If the button layout is label only...

    if (f.buttonPosition === position.textOnly) {

        app.beginPriv();

        app.alert({

            cMsg: "The specified button [" + f_name + "] has a Text-only layout.\r\rCannot import icon.",

            nIcon: 0,  // Error icon

            nType: 0,  // OK

            cTitle: "Button layout is text-only"

        });

        app.endPriv();

        return;

    }

    // Prompt user to select a file to use as the source for the button icon

    app.beginPriv();

    var oFilespec = app.browseForDoc({

        cFileFilter: 2,

        cWindowTitle: "Select an image"

    });

    app.endPriv();

    // Deal with the selected file

    if (typeof oFilespec !== "undefined") {

        // Attempt to use the selected file as the source of the button icon

        app.beginPriv();

        var nReturn = f.buttonImportIcon({

            cPath: oFilespec.cPath

        });

        app.endPriv();

        switch (nReturn) {

        case -1 :

            app.beginPriv();

            app.alert({

                cMsg: "The selected file: " + oFilespec.cPath + "\r\rcould not be opened." ,

                nIcon: 0,  // Error icon

                nType: 0,  // OK

                cTitle: "Cannot open selected file"

            });

            app.endPriv();

            break;

        case -2 :

            app.beginPriv();

            app.alert({

                cMsg: "The selected page is invalid.\r\rCannot import icon.",

                nIcon: 0,  // Error icon

                nType: 0,  // OK

                cTitle: "Selected page invalid"

            });

            app.endPriv();

            break;

        default :

            // Import was successful or user canceled

            // so there's nothing to do

        }

    }

});

The function can be called like this in the Mouse Up event of a button:

ASGJ_buttonImportIconAll(this, event.target.name);

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 17, 2016 2
Adobe Community Professional ,
Sep 19, 2016

Copy link to clipboard

Copied

Thank you King George !

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 19, 2016 0
New Here ,
Sep 27, 2016

Copy link to clipboard

Copied

Hi George,

Thank you so much for this info. I really appreciate your help and am sorry it took me a while to get back here to thank you. I was sick for about a week and have been off work.

Could I ask you one more question? Would you please clarify that I understand...I copy that code you gave me into notepad and saved it as config.js in the acrobat javascript location on my computer. Then I changed my document to have: "ASGJ_buttonImportIconAll(this, event.target.name);" instead of "event.target.buttonimporticon():".

Now when I try to use the document to click and open up a photo, nothing at all happens. I must be missing a step. Can you clarify?

Thank you!!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 27, 2016 0
Adobe Community Professional ,
Sep 27, 2016

Copy link to clipboard

Copied

What version of Acrobat are you using and what is the complete path of the directory that you saved the file? You also have to close and restart Acrobat after adding the file for it to be loaded in Acrobat.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 27, 2016 0
Most Valuable Participant ,
Sep 28, 2016

Copy link to clipboard

Copied

Make sure you enable the option to show the JS Console on errors and warnings (under Edit - Preferences - JavaScript), and try again.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 28, 2016 0
New Here ,
Oct 22, 2019

Copy link to clipboard

Copied

Hi All.  First time on this site.  I need to assign a jpg to an image field on a pdf form on the mouse up event.  I have read that you cannot pass an argument (file path/name) with "event.target.buttonimporticon()".  Is there another method that I can use.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 22, 2019 0
Most Valuable Participant ,
Oct 22, 2019

Copy link to clipboard

Copied

What you heard is not true. You can pass a file-path as an argument to buttonImportIcon, but only if the method is called from a so-called "privileged context", which generally means a script has to be installed on the local machine of the user.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 22, 2019 0
New Here ,
Oct 22, 2019

Copy link to clipboard

Copied

Thanks try67!  This may work.  I am creating a report from my "report master" PDF.  Meaning that I am the user here.  The completed password protected report is distributed to a client (renamed).  The client report is read only, with some navigation functionality embeded.

I assume the script would be called in the form.  Can you provide more detail on the script that I would need and from where in the form it would be called?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 22, 2019 0
Most Valuable Participant ,
Oct 22, 2019

Copy link to clipboard

Copied

This tutorial is a good starting point about this subject: https://acrobatusers.com/tutorials/trust-and-privilege-in-acrobat-scripts

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 22, 2019 0
New Here ,
Oct 25, 2019

Copy link to clipboard

Copied

Thanks Try67!!  Sorry for the delayed response.  Tons of irons in the fire.  Still struggling, but hope to get through it.  

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 25, 2019 0
New Here ,
Dec 03, 2019

Copy link to clipboard

Copied

Hi Try67.  Thank you for your assistance with this.  I'm finally back to working on it.  This is needed for convenience, but is not necessary functionality.  I have changed the security preferences as suggested by the article you provided.

Here's the scenario...

When using the "event.target.buttonimporticon()", without a parameter, the form opens a pop-up to browse the file system.  I want to go directly to the file search window at the path where the images reside.

I assume you are saying that I can pass the path as a parameter.

Would you be able to provide sample syntax for the parameter?  Thanks!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 03, 2019 0