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

TypeErrors in saveAs with Adobe Readers

Jesus
Registered: Mar 27 2007
Posts: 54

I'm submitting the complete sequence just in case that the replies are not being received by the Expert because I'm receivng the answers from myself.
 
Q: I have the following code in a folder level JS (not the only code):
app.beginPriv();
var myDoc = event.target;
 
myDoc.saveAs(path, formato);
 
app.endPriv();
})
 
It works OK woth Adobe Profesional but with Abobe Reader it gives me the following error:
 
TypeError: Invalid argument type.
Global.saveAs:18:XFA:topmostSubform[0].Page1[0].PrintButton1[0]:click
===> Parameter cPath.
 
I noticed that when using Adobe profesional, the variable myDoc is translated to "object Doc" but when using Reader it translate to "object Global". Maybe it has something to do with the problem.
 
Please help me!! Any Idea???
 
A:First, this function will only work in Reader if the document has "Save Rights". Do you have "Save Rights" on the PDF?
 
What version are you using? This function is considered an un-safe funtion. It could be used maliciously, but it's also very useful. So the restrictions on it have varied with just about every new version.
 
As for "event.target", this is context dependant. From where is it being called? I did a test script calling your function from a menu item and didn't have any problems on either Acrobat or Reader 8.1
 
— Answered by Thom Parker on Sat, Aug 4, 2007
Thom Parker is the president of WindJack Solutions, a software developer and a self-described adventurer. He's also a prolific contributor to the Acrobat Community.
 
Q:Thanks!
 
1- Yes the document has save right. I have tried two ways: 1- Using Adobe Pro Advanced, Enable Usage Right in Adobe reader, 2- Using a provider (Form Router)
 
2- i'm using Reader 7 and also Reader 8(not sure if is 8.0 or 8.1).
 
3- The funtion is coded in a folder level Java Script that is called from a button in the form.
 
Here is the complete .js:
 
/* saveAs Script */
 
mySaveAsjpg = app.trustPropagatorFunction(function(doc,path,formato)
 
{
 
app.beginPriv();
var myDoc = event.target;
myDoc.saveAs(path, formato);
 
app.endPriv();
})
myTrustedSpecialTaskFuncjpg = app.trustedFunction(function(doc,path,formato)
{
// privileged and/or non-privileged code above
app.beginPriv();
mySaveAsjpg(doc,path,formato);
app.endPriv();
// privileged and/or non-privileged code below
});
//
 
This is the instrucction in the button of the form:
 
MyTrustedSpecialTaskFuncjpg( this, "/c/chieftain/docs/" + FormId.rawValue + ".jpg" , "com.adobe.acrobat.jpeg");
  
Any advise please!!!!! I'm getting desesperate because this is stopping us from going to producction with my client and the client is very ofsset. I'm cosidering using Adobe Standard instead of Reader.
 
Waiting for your quiq response!! Will be very appresiated!!
 
jesus
 
— added by jesus on Sat, Aug 4, 2007
  
Q:I downloaded Adobe Reader 8.1 and now Im getting this error message:
 
RaiseErrer: An unimplemented or obsolete function was called. Doc.saveAs
 
Any help will be appresiated.
 
Regards,
 
Jesus

My Product Information:
Reader 8, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
In your code you pass a "doc" parameter down through the functions. Why not use this parameter? Except of course you have to pass down "event.target" from the button script. This is of course the appropriate context for using "event.target". It is not appropriate to use it in a folder level trusted function, since this function is not necessarily in the XFA context.

The "trustPropagator" function is completely unnecessary. You should remove it, it just complicates things.

Also try hard coding the file name and location to make sure you are not running into a naming problem. When everything else works, then put in the name variable. Standard debug and development technique, "Only test one thing at a time".

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