Skip to main content
Participant
September 16, 2016
해결됨

event.target.buttonImportIcon();

  • September 16, 2016
  • 3 답변들
  • 10252 조회

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!

이 주제는 답변이 닫혔습니다.
최고의 답변: George_Johnson

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

3 답변

Known Participant
October 22, 2019

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.

try67
Community Expert
Community Expert
October 22, 2019

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.

Known Participant
October 22, 2019

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?

Inspiring
September 16, 2016

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

}

Inspiring
September 17, 2016

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

JR Boulay
Community Expert
Community Expert
September 19, 2016

Thank you King George !

Acrobate du PDF, InDesigner et Photoshopographe
try67
Community Expert
Community Expert
September 16, 2016

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

bethc1497975작성자
Participant
September 16, 2016

Okay, thanks for the quick response!