微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在Acrobat Javascript中编写文本文件

我正在使用acrobat XI
我已经尝试输出这样的文本文件
var cMyC = "abc";
var doc = this.createDataObject({cName: "test.txt",cValue: cMyC});
this.exportDataObject({cName: "test.txt",nLaunch:0});

这是工作,但我想提供一个固定的路径,弹出窗口没有对话框请求用户选择一个保存路径

有没有办法解决问题?谢谢

解决方法

文件写入用户本地磁盘的所有Acrobat JavaScript函数都会带来安全隐患,因此对其使用有一些限制.这些函数包括doc.saveAs()和所有的数据导出函数,如doc.exportAsFDF().
正如你可以看到 here

Acrobat provides us with two modes of operation for these
functions–with a path and without a path. If no path parameter is
provided to the function,Acrobat displays a file-browser dialog. The
file browser dialog gives users control over how data is saved to
their systems. If a path is provided to the function,then no dialog
is displayed and the operation is handled silently,i.e.,the user is
not necessarily aware that data has been saved to their hard drive.
This is a security problem,so to use one of these functions in silent
mode,the function must be executed from a privileged context. This
means the code must reside in a trusted location. For example,code
executed from the Console Window,a Batch Process or a certified PDF
is privileged. When any of these functions are used with a path
parameter and executed in a non-privileged context,Acrobat will throw
an exception. The reasoning behind this restriction is,if the code
can’t be trusted,then the user has to specifically select the file
location.

Another restriction on saving data to the user’s system is that the
path specification must be a Safe Path. A safe path is one that
doesn’t point to a restricted location on the user’s hard drive or one
that might pose a security risk. Examples of these restricted
locations are the system folder and the root folder of any hard drive.
Other folders that might be restricted are dependent on the operating
system and the sensibilities of the Acrobat developers. Neither is
well documented,so it’s best to use these functions carefully.

关于“安全路径”,Acrobat JS API doc.saveAS method documentation规定:

Acrobat 6.0 introduced the concept of a safe path for JavaScript
methods that write data to the local hard drive based on a path passed
to it by one of its parameters. A path cannot point to a system
critical folder,for example a root,windows or system directory. A
path is also subject to other unspecified tests. For many methods,the
file name must have an extension appropriate to the type of data that
is to be saved. Some methods may have a no-overwrite restriction.
These additional restrictions are noted in the documentation.
Generally,when a path is judged to be not safe,a NotAllowedError
exception is thrown (see Error object) and the method fails.

确保您不能使用exportDataObject方法,因为它没有路径参数,您还可以读取here

The “cName” parameter is a required input and specifies the specific
file attachment that will be exported. Notice there is no path
parameter. There is in fact a “cPath” input to this function,but it
is no longer valid. If you try to use a path in this function,it will
fail and throw an exception. It doesn’t matter what context the
function is called from because the “cPath” parameter was removed from
all usage.

进一步参考:

> Write Text file using Acrobat Javascript
> Acrobat Javascript Save and Exit Button

原文地址:https://www.jb51.cc/js/152531.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐