Javascript 在 Acrobat 中 - 无法将值传递出对话框
Javascript in Acrobat - Can't pass values out of dialog box
我在使用 Adobe Acrobat 中的自定义对话框时遇到困难。
我的 objective 是当您单击顶部工具栏中的按钮时出现一个对话框。该对话框将包含一个可编辑的文本字段和一个 list_box。输入文本后,从列表框中进行选择,然后单击“确定”,值将传递到 PDF 文档的文本字段。现在我将它们的值 return 发送到控制台。
每次我尝试 运行 代码时,两个变量(一个用于文本字段输入,一个用于列表框选择)都未定义。我对 Acrobat 中的 javascript 还很陌生,所以这个项目正在慢慢组合在一起,就像一个科学怪人,由来自互联网的不同代码片段组成,哈哈。
任何见解将不胜感激!
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);
}
谢谢!
看看我为您编写的新提交功能。列表项存储为列表,其中具有正索引值的是所选项目。然后您可以访问所选的值。
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);
}
我在使用 Adobe Acrobat 中的自定义对话框时遇到困难。
我的 objective 是当您单击顶部工具栏中的按钮时出现一个对话框。该对话框将包含一个可编辑的文本字段和一个 list_box。输入文本后,从列表框中进行选择,然后单击“确定”,值将传递到 PDF 文档的文本字段。现在我将它们的值 return 发送到控制台。
每次我尝试 运行 代码时,两个变量(一个用于文本字段输入,一个用于列表框选择)都未定义。我对 Acrobat 中的 javascript 还很陌生,所以这个项目正在慢慢组合在一起,就像一个科学怪人,由来自互联网的不同代码片段组成,哈哈。
任何见解将不胜感激!
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);
}
谢谢!
看看我为您编写的新提交功能。列表项存储为列表,其中具有正索引值的是所选项目。然后您可以访问所选的值。
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);
}