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

Save as the same name (button)

heinzeckert
Registered: Dec 6 2008
Posts: 14
Answered

Hi,

i´m searching for a solution to create a button that saves the current dokument under the same name and overrides it, without asking me where i want to save to the file.
I´ve seen many solutions with an external JS, but in my case it has to be a solution without external files.

Can somebody help me, please?

Best wishes
Heinz Eckert

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
The reason there is an "external" JavaScript solution is because the "doc.saveAs()" function can only be run silently if it is executed from a privileged context. To do this from a script inside a PDF would be a security violation because it would be allowing a PDF, which could come from anywhere, to perform an operation on the user's system without thier knowledge.

However, there is a way to do this. If the document is established as trusted by the user, then scripts inside the PDF can perform privileged operations.

One way to establish trust is to certify the PDF with a digital signature. If the user has the public key for the signature on thier system and it is registered with Acrobat, then the PDF is considered trusted.

Acrobat 9 has another method called a trusted folder, but it's new and I haven't done much testing on it so I can't vouch for it.


Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

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

heinzeckert
Registered: Dec 6 2008
Posts: 14
Der Thomp,

thank you for your quick answer.
Because of this im testing to external option.

i´ve an exam.js with only this code:

// SaveAs Function
var mySaveDoc = app.trustedFunction(function(doc) {

app.beginPriv();
var myPath = app.getPath("user", "documents") + "test123.pdf";
doc.saveAs(myPath);
app.endPriv();

});


on my button in my pdf is this script:
this.mySaveDoc(event.target);


But if i push the button, my debugger responses:

TypeError: doc.saveAs is not a function
7:Folder-Level:App:exam.js

Can you please help me again. I dont know why this happens.

Best wishes
Heinz Eckert
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
Did you create the form in Acrobat or LiveCycle Designer?
heinzeckert
Registered: Dec 6 2008
Posts: 14
I created all in Acrobat
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
The code in your button should be:

mySaveDoc(this);
heinzeckert
Registered: Dec 6 2008
Posts: 14
Oh, thank you very much!
Im such an idiot :)

But, is there an option to save the file in the current used folder?
My file would be opened in any folder on the lokal pc. Can i save it in this folder, however i dont know in which folder the user opened the pdf?

I just want to override the existing file.
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
If you just want to overwrite the existing file, do this in your function:

doc.saveAs(doc.path);
George
heinzeckert
Registered: Dec 6 2008
Posts: 14
thank you, that was a big help!