These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Save a text file to local disk

vishnuuppar
Registered: May 3 2011
Posts: 3

Hi All,
 
I am trying to save a text file to local disk and want to read/write on it,
 
below is the code for DataObject
 
var myFunc = app.trustedFunction(function()
{
app.beginPriv();
var str = this.pageNum+1;
str +="*"+this.path;
this.createDataObject("links.txt",str);
this.exportDataObject({cName:"links.txt",cDIPath:"user,documents"});
this.removeDataObject("links.txt");
rep.writeText(str);
rep.save("/c/Documents and Settings/ahsan/My Documents/links.txt");
app.endPriv();
});
  
But I am getting error on this.
 
Please help me.
 
Thanks in Advance

My Product Information:
Acrobat Standard 8.2.6, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
If you lookup the entry in the Acrobat JavaScript Reference at for the "doc.exportDataObject()" you'll see these two notes:

Note: Beginning with Acrobat 6.0, if the parameter cDIPath is non-null, a NotAllowedError (see Error object) exception is thrown and the method fails.

And on the cDIPath argumernt

Note: (Acrobat 6.0) The use of this parameter is no longer supported and should not be used. See the security notes above.


So exporting a data object won't work any more:(

You've got the right idea with the report object, but the code is out of place here. I don't see where this object is created and it cannot be saved directly to a text file. It can only be saved to PDF.

The Acrobat JavaScript environment is heavily sandboxed. There are very few ways to write directly to the user's local file system. But there are a couple of ways to write a text file to the user's file system. The easiest method is to use the "doc.saveAs()" function to convert a PDF into a text file.

So, use the report object to create a PDF with the text you want, then "open" the report to get the "doc" object and then save the doc object to text using the cConvID parameter.


Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

vishnuuppar
Registered: May 3 2011
Posts: 3
Thanks a lot Thom Parker.

I am able to save the text file to local by using Doc object saveAs with cConvID parameter.

Thanks
Vishnu