【问题标题】:Javascript in Acrobat - Can't pass values out of dialog boxAcrobat 中的 Javascript - 无法将值传递出对话框
【发布时间】:2020-06-23 06:31:58
【问题描述】:

我在使用 Adob​​e Acrobat 中的自定义对话框时遇到了困难。

我的目标是在您单击顶部工具栏中的按钮时出现一个对话框。该对话框将包含一个可编辑的文本字段和一个 list_box。输入文本后,从列表框中进行选择,然后单击确定,这些值将传递到 PDF 文档上的文本字段。现在我将它们的值返回到控制台。

每次我尝试运行代码时,两个变量(一个用于文本字段条目,一个用于列表框选择)都返回未定义。我对 Acrobat 中的 javascript 非常陌生,所以这个项目就像一个由来自互联网的不同代码 sn-ps 组成的科学怪人一样慢慢地走到了一起,哈哈。

任何见解将不胜感激!

var timeDialog = {
    initialize: function(dialog) {this.loadDefaults(dialog);},
        commit: function(dialog) { 
            var timeEntry = dialog.store()["tetb"]
            var techEntry = dialog.store()["tnlb"]
          },
        loadDefaults: function (dialog) {
            dialog.load({
                "tnlb":
                {
                    "Jimmy John": +2,
                    "Papa John": +1,
                    "Great Gatsby": +0
                }
            })
        },
        description: 
        {
            name: "Time Dedicated", 
            elements: 
            [
                { 
                    type: "view",  
                    elements: 
                    [
                        {
                            type: "cluster",
                            elements:
                            [
                                {
                                    name: "Time spent on Request (minutes):", 
                                    type: "static_text"
                                },
                                {
                                    type: "edit_text",
                                    item_id: "tetb",
                                    char_width: 5
                                },
                                {
                                    name: "Technician:", 
                                    type: "static_text"
                                },
                                {
                                    item_id: "tnlb", 
                                    type: "list_box",
                                    width: 200,
                                    height: 60
                                }
                            ]
                        },
                        {
                            type: "ok_cancel"
                        }
                    ]
                }
            ]
        }
    }

if( "ok" == app.execDialog(timeDialog)) { 
    var today = new Date();
    var time = today.getHours() + "." + today.getMinutes() + "." + today.getSeconds();
    var TEMP_FIELD_NAME = timeDialog.timeEntry
    var textValue = timeDialog.techEntry;
    console.println(TEMP_FIELD_NAME); 
    console.println(textValue); 
}

谢谢!

【问题讨论】:

    标签: javascript variables dialog adobe acrobat


    【解决方案1】:

    看看我为你写的新提交函数。列表项存储为列表,其中具有正索引值的项是选定项。然后您可以访问选定的值。

    var timeDialog = {
        initialize: function (dialog) { this.loadDefaults(dialog); },
        commit: function (dialog) {
            this.timeEntry = dialog.store()["tetb"];
            var items = dialog.store()["tnlb"]
            for (var item in items) {
                if (items[item] > 0) {
                    this.techEntry = item;
                    break;
                }
            }
        },
        loadDefaults: function (dialog) {
            dialog.load({
                "tnlb":
                {
                    "Jimmy John": +2,
                    "Papa John": +1,
                    "Great Gatsby": +0
                }
            })
        },
        description:
        {
            name: "Time Dedicated",
            elements:
                [
                    {
                        type: "view",
                        elements:
                            [
                                {
                                    type: "cluster",
                                    elements:
                                        [
                                            {
                                                name: "Time spent on Request (minutes):",
                                                type: "static_text"
                                            },
                                            {
                                                type: "edit_text",
                                                item_id: "tetb",
                                                char_width: 5
                                            },
                                            {
                                                name: "Technician:",
                                                type: "static_text"
                                            },
                                            {
                                                item_id: "tnlb",
                                                type: "list_box",
                                                width: 200,
                                                height: 60
                                            }
                                        ]
                                },
                                {
                                    type: "ok_cancel"
                                }
                            ]
                    }
                ]
        }
    }
    
    if ("ok" == app.execDialog(timeDialog)) {
        console.println(timeDialog.timeEntry);
        console.println(timeDialog.techEntry); 
    }
    

    【讨论】:

      猜你喜欢
      • 2021-12-13
      • 2023-01-10
      • 2013-08-27
      • 2021-10-22
      • 1970-01-01
      • 2013-07-06
      • 1970-01-01
      • 1970-01-01
      • 2013-02-25
      相关资源
      最近更新 更多