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

Save as Trusted Function

srprice
Registered: Sep 19 2007
Posts: 138
Answered

I'm trying to run a batch that will perform a Save As. I understand that Save As must be executed as a trusted function and place as a folder leverl javascript.

Here is my Javascript:

// Save As EPS function
var saveAs = app.trustedFunction(
function()
{
app.beginPriv();
var name = this.documentFileName;
var n = name.split(".");
this.saveAs({
cPath: "/c/junk/test/in/" + n + ".eps",
cConvID: "com.adobe.Acrobat.eps"
});
app.endPriv();
}
);

When I call the saveAs() function in my batch I get the following error message:

MissingArgError: Missing required argument.
this.saveAs:1:Batch undefined:Exec
===> Parameter cPath.

Any help would greatly be appreciated.

try67
Expert
Registered: Oct 30 2008
Posts: 2398
You can't use an array in a string. You need to access one of the items in the array.
There might be other problems with your code, like the usage of the "this" object.

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

radzmar
Expert
Registered: Nov 3 2008
Posts: 1202
Your variables should never be named like existing functions or properties of Acrobat.
So "var saveAs" can cause unexpected problems.
You better rename it to something individual like "var SaveAsEPS" or "var MySaveAs".

radzmar
LoveCycle Blog
Documents you need:
LiveCycle Designer ES2 Docs

srprice
Registered: Sep 19 2007
Posts: 138
Thanks so much for both of your responses. I modified the .js and now it works. Here is the new script.

// Save As EPS function
var saveAsEps = app.trustedFunction(
function()
{
app.beginPriv();
var name = this.documentFileName;
var n = name.split(".");

for (i = 1; i< n.length; i++)
console.println(n[0]);

this.saveAs({
cPath: "/c/junk/test/in/" + n[0] + ".eps",
cConvID: "com.adobe.acrobat.eps"
});
app.endPriv();
}
);
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Glad to hear it, but you can still improve it. This loop, for example, makes no sense:
for (i = 1; i< n.length; i++)
console.println(n[0]);

Either change what you print to n[i], if you want all tokens, or remove the loop part, if you want just the first one.

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

srprice
Registered: Sep 19 2007
Posts: 138
If I change it to n[i] then I only get 1 file with a filename of undefined.

If I take the loop out I get a security error.

If I leave it at n[0] I get all the files converted with the same document filename.
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Change the start of the loop to 0, not 1.
I don't really understand what you're trying to achieve with this loop, anyway...

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

srprice
Registered: Sep 19 2007
Posts: 138
I running this as a batch. I have over 100 files that I need to convert to and eps. I need to maintain the original filename just perform a saveAs to an eps file.

If I make the change as suggested the filename is changed to undefined.eps
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Doesn't make sense. Printing (or not printing) the variable out to the console will have no effect on it.

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

Merlin
Acrobat 9ExpertTeam
Registered: Mar 1 2006
Posts: 766
Doesn't make sense.
You don't need any line of JavaScript to batch-save as EPS and keep original names !

As we say here : you reinvented the wheel…

;-)))

[url=http://imagesinsolites.free.fr/parkimages/batchsaveaseps-1267150856066.jpg][img]http://imagesinsolites.free.fr/parkimages/batchsaveaseps-1267150856066.jpg[/img][/url]
srprice
Registered: Sep 19 2007
Posts: 138
You are absolutely right. I knew that save as had to be run as a trusted function and didn't even think to check the obvious.

Thats what happens when you are knee deep in code all day, I don't look for the easy ways, I look for the code ways. :-)!!!
Merlin
Acrobat 9ExpertTeam
Registered: Mar 1 2006
Posts: 766
;-)

"Knee deep" in french : "la tête dedans" (literally : head inside)