gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 02:38:45 25 4
gpt4 key购买 nike

我正在使用 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 方法来做,因为它没有 path 参数,你也可以阅读 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.

进一步引用:

关于javascript - 如何在 Acrobat Javascript 中编写文本文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17422514/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com