0 Replies Latest reply on Mar 4, 2015 5:37 AM by JC-TheSpaniard

    PDF Javascript Trusted DialogBox

    JC-TheSpaniard

      Hi there,

       

      I am currently learning to develop in Javascript within Acrobat and I am playing around with Trusted Dialog Boxes.  I have read and search everywhere and I can NOT seem to get my code to work.  This code came out of the Acrobat XI SDK API REFERENCE (page 149 - 151).  I am currently using Acrobat X Pro to develop.  So here are my questions:

       

      1. Why is it that this code does NOT work or show up the dialog box?

      2. How can I add the Tools Menu item?

      3. I tried adding a PUSH button with the code also but it does not work. Not sure why.

      4. Where am I suppose to add this script?  I am currently placing the script inside the Action Wizard as a Javascript.

       

      Code:

       

      myDialog = app.trustedFunction(function()

      {

        app.beginPriv();

        var dialog = ANTrustPropagateAll({

        initialize:function(dialog) {

        this.data = {}; // An object to hold dialog data

        app.beginPriv();

        dialog.load({ "emai": "Email: " + identity.email });

        app.endPriv();

        },

        commit:function (dialog) { // Called when OK pressed

        var results = dialog.store();

        console.println("Your name is " + results["name"] );

        this.data.name = results["name"];

        },

        brws: function (dialog) {

        app.beginPriv();

        var oRetn = app.browseForDoc();

        if ( typeof oRetn != "undefined")

        this.data.oRetn = oRetn;

        app.endPriv();

        },

        doDialog:function() {

        app.beginPriv();

        var retn = app.execDialog(this);

        app.endPriv();

        return retn;

        },

        description: {

        name: "Open File & Populate Info Field",

        align_children: "align_left",

        elements:

        [

        {

        type: "view",

        align_children: "align_left",

        elements:

        [

        {

        type: "view",

        align_children: "align_row",

        elements:

        [

        {

        type: "static_text",

        name: "Name: "

        },

        {

        item_id: "name",

        type: "edit_text",

        alignment: "align_fill",

        width: 300,

        height: 20

        },

        ]

        },

        {

        type: "static_text",

        item_id: "emai",

        name: "Email: ",

        char_width: 25

        },

        {

        type: "gap",

        height: 10

        },

        {

        type: "view",

        align_children: "align_row",

        elements:

        [

        {

        type: "button",

        name: "Browse",

        item_id: "brws"

        },

        {

        type: "ok_cancel",

        ok_name: "Ok",

        cancel_name: "Cancel"

        }

        ]

        }

        ]

        }

        ]

        }

        });

        app.endPriv();

        try { // Protect against user pressing the Esc key

        // After everything is set up, run the dialog box using the doDialog

        // function, defined in the object dialog.

        var retn = dialog.doDialog();

        app.beginPriv();

        // If the user clicked the Ok button and there is oRetn data we load

        // the requested file using app.openDoc(), a restricted method.

        if ( (retn == "ok") && dialog.data.oRetn ) {

        var oDoc = app.openDoc({

        cPath: dialog.data.oRetn.cPath,

        cFS: dialog.data.oRetn.cFS

        });

        if ( !oDoc.info.Author )

        oDoc.info.Author = dialog.data.name;

        }

        app.endPriv();

        } catch(e) {}

      })

       

      And then the API reference says:

       

      This dialog box can be activated from a button or, more appropriately, from a menu item or a toolbar

      button. For example, place the following code in a User JavaScript file to add a menu item to the Tools

      menu.

      app.addMenuItem( { cName: "myDialog", cUser: "My Cool Dialog",

      cParent: "Tools", cExec: "myDialog()", nPos: 0 } );

       

      Not sure where to add the code to make a button or Menu item.  What does it mean "place the following code in a User JavaScript file to add a menu item to the Tools menu.

       

      Any help understanding this will be greatly appreciated!!!