我一直在写一些JavaScript来填写PDF表单的字段。我最初在Adobe的“动作向导”中编写了代码。当时我没有意识到我将其添加到本地应用程序中,而不是表单本身。所以我然后将其复制到上的按钮上,现在它不起作用。

编码:

/* Test to read in a file and update the fields*/
var dataFrom = null;
//Grab the current path and update it to indicate the TempInfo location
var strPath = this.path;
strPath = strPath.slice(0,-12);
strPath = strPath + "TempInfo.txt"

//Get data from TempFile into array, display message if no file found
try{
  var dataStream = util.readFileIntoStream(strPath);
  var dataFrom = util.stringFromStream(dataStream);
}catch(e){
app.alert("Temp file not found");
}

//Put the data into an array and update the fields
var strTest = new Array();
strTest = dataFrom.split(/\n/);

getField("Username").value = strTest[0];
getField("UID").value = strTest[1];

//Clear the data
dataStream = null;
dataFrom = null;
strTest = null;


我正在获取app.alert“找不到临时文件”,因此“ var dataStream = readFileInfoStream(strPath);”没有读入文件。我做了app.alerts来验证strPath变量是否具有正确的路径,并通过一个app.alerts来验证dataStream是否为null。由于我是从“操作向导”复制的,因此我不确定为什么它不起作用。

只是使这个变得有点奇怪(至少对我来说),如果我打开JavaScript编辑器并突出显示代码,它就可以正常工作。

最佳答案

对于util.readFileIntoStream方法,当指定cDIPath参数时,只能在特权上下文中执行该方法,这意味着在批处理,控制台事件或Action中。除非您创建“受信任的功能”,否则在文档上下文中执行该功能将无效。

阅读本文以了解如何在非特权上下文中执行特权方法...
http://help.adobe.com/en_US/acrobat/acrobat_dc_sdk/2015/HTMLHelp/index.html#t=Acro12_MasterBook%2FJS_Dev_Contexts%2FExecuting_privileged_methods_in_a_non-privileged_context.htm&rhsearch=trusted%20function&rhsyns=%20

关于javascript - Action 向导中的Adobe Javascript与表单按钮,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46796831/

10-12 00:19
查看更多