Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Button 'SaveAs'

Avatar

Level 2
I have been trying to setup a pdf to save to a predefined path with a click on a button.



I tried this code :



var aDocs = app.activeDocs;

var myDoc = aDocs[0];

myDoc.saveAs("C:\\" + Title.rawValue + ".pdf");



But i have this error :



myDoc has no properties

3:XFA:formulaire1[0]:#subform[0]:Bouton1[0]:click



Thanks in advance...
19 Replies

Avatar

Former Community Member
You can save the current doc using the app.execMenuItem("SaveAs") this will bring up a dialog and allow the user to select the location for the saveed file. You cannot indicate where the file will go without certifying the document (Acrobat does not allow you to do unattended operations like that without the users knowledge).

Avatar

Level 2

Hi,

I found this thread by accident. I have one question about the SaveAs. I want to use app.execMenuItem("SaveAs"). But I also want to create a default name to save this document. I have a text field "serial number" that will be filled out by the user and I want to use this serial number as document name. How can I realise it? - I'm a Script-Newbie.

Dennis

thorlabs_hl

Avatar

Former Community Member

No can do ......you cannot automatically save something without the user entering the file name unless you certify the document which will bring in a new set of issues.

Paul

Avatar

Level 2

Hi,

I don't want to autosave. It was mentioned in this thread that this is not possible. I want to suggest the user a suitable file name. The user can edit it if he want. It is like I'm saying: "This would be a good name. You should go with it."

Dennis

thorlabs_hl

Avatar

Former Community Member

I understand but the command does not work that way. The command basically will press the File /SaveAs menu item.

Paul

Avatar

Level 2

Ah. OK. I understand. But is there an other way to realize it. A easy way? I'm a newbie. If there is no way I just place a note next to the save button.

Dennis

thorlabs_hl

Avatar

Level 2

Thanks for the help. Even this "no" is a helpful answer for me. I stay with my note next to the save button.

Dennis

thorlabs_hl

Avatar

Level 2
Thanks for your answer.



I have seen your previous posts about 'SaveAs', but my englich isn't very good and i don't understand everything.



I tried to do this, with the solution whow is explain in this post :

http://www.adobeforums.com/webx/.59b74b77



But i have this error



event.target.myTrustedSpecialTaskFunc100 is not a function

1:XFA:formulaire1[0]:#subform[0]:Bouton1[0]:click



-----------------

The code of the button :

event.target.SaveAsFunc(event.target);

-----------------



The JS code :



mySaveAsPO = app.trustPropagatorFunction(function(myDoc, path)

{

app.beginPriv();

var myDoc = event.target;

return retn = myDoc.saveAs(path);

app.endPriv();

});

SaveAsFunc = app.trustedFunction(function(myDoc, path)

{

app.beginPriv();



var av = formulaire1.subform1.departement_inclusion.rawValue



var g = "/c/PDF_Folder/" + av + ".pdf



var retn = mySaveAsPO(myDoc, g);



app.endPriv();

return retn;

});

-------------

Thanks for your help

Avatar

Former Community Member
You will have to certify your document before the privilidged function will run. The certification allows the user to set up a trust - that he will allow script to run.

Avatar

Level 2
I have certified my document but i always have the same message :



event.target.SaveAsFunc is not a function

1:XFA:formulaire1[0]:#subform[0]:Bouton1[0]:click



In the 'hierarchy', i've saved the script under Form1.



I don't understand this message : An error in the script, or the script is not found?



Thank's for your help

Avatar

Level 2
Here is my code :



Button code : event.target.SaveAsFunc(event.target);



Script code (i created this script with a right click on Form1 in the hierarchy window, and wrote the code in the script editor)



mySaveAsPO = app.trustPropagatorFunction(function(myDoc, path)

{

app.beginPriv();

var myDoc = event.target;

return retn = myDoc.saveAs(path);

app.endPriv();

});

SaveAsFunc = app.trustedFunction(function(myDoc, path)

{

app.beginPriv();



var av = formulaire1.subform1.departement_inclusion.rawValue



var g = "/c/PDF_Folder/" + av + ".pdf



var retn = mySaveAsPO(myDoc, g);



app.endPriv();

return retn;

});



I don't know if it is the good process ?

Avatar

Former Community Member
Don't do it in a scripting object to begin with. Get it to work outside of the script object ....then we will make a script object out of it.

Avatar

Level 2
Ok, i must create a JS script : mySaveAsPO.js



but I do not understand how the pdf knows which script use ?

Avatar

Former Community Member
That js script goes into a folder in the Acrobat installation and when Acrobat loads that script will be picked up (it is global in scope). Now you can reference it as you have been doing.

Avatar

Level 2
Ok, i know why i've got this error, I had forgotten a quote in the code.



now, i have this error :



formulaire1 is not defined

12:XFA:formulaire1[0]:#subform[0]:Bouton1[0]:click



thank you for your help and patience

Avatar

Level 2
Sorry but i can't resolve this error



formulaire1 is not defined

12:XFA:formulaire1[0]:#subform[0]:Bouton1[0]:click



In my hierarchy, there is :

formulaire1

subform

item1

item2

...



is this code wrong :

var av = formulaire1.subform1.departement_inclusion.rawValue



And a last question,

is it possible to save a PDF form, on a simple PDF (a picture of the form).



Thanks for your help

Avatar

Former Community Member
Its hard to tell what is wrong without seeing the form and getting the code in context. Send it to livecycle8@gmail.com and I will have a look.



You can not save as an image PDF out of Designer. You would create the PDF, then open it in Acrobat then you can export as an image.