6

尝试使用 AcroJS 写入带有 Adob​​e Acrobat Reader 的文本文件。

作为一个概念,我了解了如何在 Acrobat 中使用受信任的函数,但是当我尝试运行以下示例以使用 this.saveAs(..) 以不同的名称保存(与原始问题不同)的 pdf 表单时收到错误。我的问题有两个;

1-为什么我会收到“安全设置阻止访问此属性或方法”错误,我该如何摆脱它?

javascript 文件夹中的受信任函数是 follwos (copeid off the web)

  var mySaveAs = app.trustedFunction( function(cFlName)
   {
        app.beginPriv();
       try{
             this.saveAs(cFlName);
           }
         catch(e){
              app.alert("Error During Save " + e.message );
              }
         app.endPriv();
    });

我正在调用文档中的受信任函数作为 follwos 并期望在“C:/test”中生成一个名为 sample.pdf 的文件

     if(typeof(mySaveAs) == "function")
     { 
         mySaveAs("/C/test/sample.pdf");
     }
     else
     {
      app.alert("Missing Save Function");
     }

2-如何写入文本文件?在这里,我想从 PDF 表单中提取一些字段值并将它们写入文本文件(或 XML)!

4

1 回答 1

3
  1. 您可能已经猜到,这是一种防止恶意脚本造成破坏的安全措施。您需要关闭安全设置。为此,按 Ctrl+K 进入首选项,转到增强安全选项卡并禁用它。

    有关增强安全性的其他信息,请参阅:http: //www.adobe.com/devnet-docs/acrobatetk/tools/AppSec/enhanced.html

  2. 据我所知,没有任何函数可以让您将任意数据写入文本文件或 XML 文件。但是,您有几个选择:

    • 使用Doc.exportAsText(文本)和Doc.exportAsFDF(XML)从精心设计的字段中导出数据。这不是很简单而且有点尴尬,但它确实有效。

    • Use Net.HTTP.request or Net.SOAP to send data to an ad-hoc local web server (eg: something simple, running Python or PHP) and let them handle the request. This allows you to do pretty much anything you want, but requires more work to setup the server.

    See: Acrobat JS API Reference

于 2013-01-09T18:00:07.347 回答