Adobe Javascript的行动向导与表单按钮
问题描述:
我一直在写一些javascript来填写一个PDF表单的字段。我最初在Adobe的“Action Wizard”中编写了代码。当时我没有意识到我将它添加到我的本地应用程序中,而不是表单本身。所以我把它复制到了from的一个按钮上,现在它不起作用了。Adobe Javascript的行动向导与表单按钮
代码:
/* 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数据流= readFileInfoStream(strPath中);”没有在文件中读取。我做了app.alerts来验证strPath变量是否有正确的路径,并验证dataStream是否为空。正是我从操作向导中复制它,我不确定它为什么不工作。
只是为了让这个有点奇怪(至少对我来说),如果我打开JavaScript编辑器并突出显示代码,它可以正常工作。
答
对于util.readFileIntoStream方法,当指定cDIPath参数时,该方法只能在批处理,控制台事件或操作期间的特权上下文中执行。除非您创建可信功能,否则它在文档上下文中执行时不起作用。
阅读本如何理解与执行的非特权背景特权方法... 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控制台中,我跑了:'app.getPath(“user”,“javascript”);'并取回“undefine”,为'app'做了同样的事情,并返回了结果,但我没有权限到该文件夹。有没有一种方法可以定义用户文件夹? –
如果您需要将此代码分发给其他人,则最好将其作为动作或自定义命令执行。如果您将其设置为可信功能,则用户也需要安装该功能。但是,作为回应,我猜你正在使用Windows。请参阅这篇文章的说明... https://www.pdfscripting.com/public/Installing_Automation_Tools.cfm – joelgeraci
真的很感谢信息和链接。我将查看文件夹级脚本的说明,并查看自定义命令,并选择最适合的方式。 –