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

Saving a report on disk as txt file

saboorthakur
Registered: Jun 25 2009
Posts: 56
Answered

Hi all!

I am in great problem since last couple of days. I tried a lot to save a report as text file using a trustedFunction but it always prompted me NotAllowedError. Kindly help me. my code is as

var myFunc = app.trustedFunction(function()
{
app.beginPriv();
var str = this.pageNum+1;
str +="*"+this.path;
var rep = new Report();
rep.writeText(str);
rep.save("/c/links.txt");
app.endPriv();
});

Kindly help. please...

My Product Information:
Acrobat Pro 9.0, Windows
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Probably because you're trying to save it to the root folder, which is not a "safe path".
From the reference file: "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."

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

saboorthakur
Registered: Jun 25 2009
Posts: 56
Thanks for your reply. I tried to save the report on d:\temp but it still doesn't allow me to save there.
saboorthakur
Registered: Jun 25 2009
Posts: 56
No i tried this.

var myFunc = app.trustedFunction(function()
{
app.beginPriv();
var str = this.pageNum+1;
str +="*"+this.path;
var rep = new Report();
rep.writeText(str);
rep.save("/c/Documents and Settings/ahsan/My Documents/links.txt");
app.endPriv();
});
but no progress
try67
Expert
Registered: Oct 30 2008
Posts: 2398
You can't save a report object as a text file. It's a PDF.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

saboorthakur
Registered: Jun 25 2009
Posts: 56
any way to save as a text file. if report doesn't allow then can i do it using doc.
try67
Expert
Registered: Oct 30 2008
Posts: 2398
You can use the DataObject methods to create a plain text file.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

saboorthakur
Registered: Jun 25 2009
Posts: 56
so then how can i store it on the disk? kindly give me some example.
try67
Expert
Registered: Oct 30 2008
Posts: 2398
You should start by looking in the reference file for createDataObject, exportDataObject and the other related methods.
If after reading it you still have questions you can post them here.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

saboorthakur
Registered: Jun 25 2009
Posts: 56
i did but i am stuck. kindly give me a little example to save the dataobject on disk drive as text
saboorthakur
Registered: Jun 25 2009
Posts: 56
see my 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();
});
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Where are you stuck? Were you able to create a new DO? Set its contents?

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

saboorthakur
Registered: Jun 25 2009
Posts: 56
thanks for your great concern, kindly ignore the rep.writeText and rep.save lines.
try67
Expert
Registered: Oct 30 2008
Posts: 2398
The problem is here:
cDIPath:"user,documents"

This is not the correct way to specify a path. You need to use app.getPath first.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

saboorthakur
Registered: Jun 25 2009
Posts: 56
Now i changed it

var myFunc = app.trustedFunction(function()
{
app.beginPriv();
var str = this.pageNum+1;
var path = app.getPath("user","documents");
str +="*"+this.path;
this.createDataObject("links.txt",str);
this.exportDataObject({cName:"links.txt",cDIPath:path});
this.removeDataObject("links.txt");
app.endPriv();
});

i got NotAllowedError at exportDataObject
try67
Expert
Registered: Oct 30 2008
Posts: 2398
You can't specify the cDIPath at all. You need to remove it and the user will be prompted where to save the file.
Also, from which context are you running this?

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

saboorthakur
Registered: Jun 25 2009
Posts: 56
I am running it from a button action. actually i don't want user interaction for that. my actual requirement is to create a shortcut of the current opened file on button click. if there is any way to create shortcut then i will not require the txt file.
try67
Expert
Registered: Oct 30 2008
Posts: 2398
I don't understand what you mean by "create a shortcut of the current opened file" ...

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

saboorthakur
Registered: Jun 25 2009
Posts: 56
when the user clicks the button i want to create a windows shortcut .lnk file to the currently opened pdf document. put this shortcut on the user's desktop. I am using a folder level script. I tried to find out a way to create a the lnk file but didn't work for me. Then i tried using the wsh(Windows Script Host) file. can i call a WSH from a folder level javascript and the WSH does the rest. After much effort i found out that proabably acrobat doesn't allow this. now i want to save some info in a text file without user interaction which according to you is also not allowed. I think this should be allowed to a folder level script. please give me your thoughts on this issue or any suggestions how can i resolve this.. ?
try67
Expert
Registered: Oct 30 2008
Posts: 2398
I see. It used to be possible to save (some) files from within Acrobat without user interaction, but with the newer versions its not anymore. Some will say its a bad thing (developers who want access to the file system), and some will say its a good thing (users who don't want files saved on their machine without them knowing about it).

Maybe it's possible to achieve what you want to do with a VB script (but I doubt it), or with a plugin.
I can't really help you with either... but maybe someone else can.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com