如何在Acrobat Javascript中编写文本文件 [英] How to write a text file in Acrobat Javascript

查看:122
本文介绍了如何在Acrobat Javascript中编写文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用acrobat XI
我尝试输出这样的文本文件

I am using acrobat XI I have tried output a text file like this

var cMyC = "abc";
var doc = this.createDataObject({cName: "test.txt", cValue: cMyC});
this.exportDataObject({cName: "test.txt", nLaunch:0});

这是有效的,但我想提供一个固定的路径,并且没有弹出对话框来请求用户选择保存路径

This is working , but I would like to provided a fixed path and no dialog is popup to request the user choose a saving path

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

Are there any way to fix the problem? thanks

推荐答案

将文件写入用户本地磁盘的所有Acrobat JavaScript函数都存在安全风险,因此存在一些限制他们的使用。这些函数包括 doc.saveAs()和所有数据导出函数,如 doc.exportAsFDF()。< br>

您可以阅读此处:< br>

All Acrobat JavaScript functions that write a file to the user’s local disk pose a security risk, so there are some restrictions placed on their use. These functions include doc.saveAs() and all of the data export functions, like doc.exportAsFDF().

As you can read here:


Acrobat为这些
函数提供了两种操作模式 - 带路径且没有路径。如果没有路径参数是
提供给该函数,Acrobat将显示文件浏览器对话框。
文件浏览器对话框使用户可以控制如何将数据保存到他们的系统
。如果为该函数提供了路径,则不会显示对话框
,并且静默处理该操作,即,用户是
,不一定知道数据已保存到其硬盘驱动器中。
这是一个安全问题,因此要在静默
模式下使用其中一个函数,必须从特权上下文执行该函数。此
表示代码必须位于受信任位置。例如,从控制台窗口,批处理或经过认证的PDF
执行的代码
具有特权。当任何这些函数与路径
参数一起使用并在非特权上下文中执行时,Acrobat将抛出
异常。这个限制背后的原因是,如果代码
不可信,那么用户必须专门选择文件
location。

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.

将数据保存到用户系统的另一个限制是
路径规范必须是安全路径。安全路径是
未指向用户硬盘驱动器上的受限位置或可能造成安全风险的
。这些受限制的
位置的示例是系统文件夹和任何硬盘驱动器的根文件夹。
可能受限制的其他文件夹取决于运行
系统和Acrobat开发人员的敏感度。也没有详细记录
,所以最好仔细使用这些函数。

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 方法文档声明:

About "Safe Paths", the Acrobat JS API doc.saveAS method documentation states:


Acrobat 6.0引入了JavaScript
方法的安全路径概念,该方法根据通过其中一个参数传递
的路径将数据写入本地硬盘驱动器。路径不能指向系统
关键文件夹,例如根目录,窗口或系统目录。
路径也受其他未指定的测试的影响。对于许多方法,
文件名必须具有适合于保存
的数据类型的扩展名。某些方法可能具有无覆盖限制。
这些附加限制在文档中注明。
通常,当路径被判断为不安全时,抛出NotAllowedError
异常(请参阅Error对象),方法失败。

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 方法来做,因为它没有路径参数,你也可以阅读这里

For sure you can't do it with the exportDataObject method, since it has no path parameter, as you can also read here:


cName参数是必需的输入,并指定特定的
文件附件将被出口。请注意,没有路径
参数。事实上这个函数有一个cPath输入,但
不再有效。如果您尝试在此函数中使用路径,则
将失败并抛出异常。调用
函数的上下文无关紧要,因为cPath参数已从
所有用法中删除。

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.

进一步参考:

Further references:

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

这篇关于如何在Acrobat Javascript中编写文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆