简体   繁体   中英

Write text file using acrobat javascript

Trying to write to a text file w/ Adobe Acrobat Reader utilizing AcroJS.

As a concept I got how to use trusted functions in Acrobat but when I tried to run following example to save (different problem then the original) the pdf form under a different name using this.saveAs(..) received an error. My question is two fold;

1- Why do I get "Security settings prevent access to this property or method" error and how do I get rid of it?

trusted function in javascript folder is as 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();
    });

I am calling the trusted function from the doucment as follwos and expecting a file with the name sample.pdf will be generated inside "C:/test"

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

2- How do I write to a text file? Here I want to extract some field values from the PDF form and write those into a text file (or XML)!

  1. As you might have guessed, it's a security measure to prevent malicious scripts from causing havoc. You'll need to turn down the security settings. To do this, Ctrl+K into Preferences, go to the Enhanced Security tab and disable it.

    For addition information on Enhanced Security, refer to: http://www.adobe.com/devnet-docs/acrobatetk/tools/AppSec/enhanced.html

  2. As far as I know, there aren't any functions that will allow you to write arbitrary data to a text file or XML file. However, you have a couple of options:

    • Use Doc.exportAsText (text) and Doc.exportAsFDF (XML) to export data from carefully crafted fields. This isn't very straightforward and a little awkward, but it works.

    • 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM