Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)!

like image 452
Karaman Avatar asked Dec 07 '12 09:12

Karaman


People also ask

How do I use JavaScript in Adobe Acrobat?

The JavaScript debugger in Acrobat lets you review your code line by line, set breakpoints, and inspect variables using the debugger dialog. To enable JavaScript Debugger, go to Edit > Preferences > JavaScript, and then select the Enable JavaScript debugger after Acrobat is restarted option.

Does Adobe support JavaScript?

To enable JavaScript in Adobe Acrobat Reader Open Adobe Acrobat Reader. Go to Edit > Preferences. In Categories, click JavaScript. In the JavaScript section, check Enable Acrobat JavaScript.

Can JavaScript work in a PDF?

About JavaScript in Acrobat The JavaScript language was developed by Netscape Communications as a means to create interactive web pages more easily. Adobe has enhanced JavaScript so that you can easily integrate this level of interactivity into your PDF documents.


1 Answers

  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

like image 196
999999 Avatar answered Sep 20 '22 17:09

999999