Expand my Community achievements bar.

Join us in celebrating the outstanding achievement of our AEM Community Member of the Year!

How to save and then close a PDF Using Acrobat 9 (URGENT)

Avatar

Level 1

I have been looking for a soultion for long time now but

couldn't find any.

I'm using a dynamic PDF form desgined using LC Desginer and created a button that should save the current opened form in the same location (no need to define the location because what I want to use is the command File -> Save) and then close the application (I'm using Acrobat 9 Pro Extended).

I tried many scripts and gone throw JavaScriptfor Acrobat® API Reference but no luck.

Once I click on the button I get the following error: NotAllowedError: Security settings prevent access to this property or method.

Will you please help in this issue as it took long time and my project manager is pushing to get resolved ASAP.

Guys, I'm new to this kind of tecnology so please be patient with me.

Thanks in advance for your valuable help.

The code I used in click event of the button is as follow:

     var myDoc = app.newDoc();

     myDoc.saveAs();

     myDoc.closeDoc(true);

}

catch (e)

{

     xfa.host.messageBox(""+e);

}

I used this earlier and got the same error:

try{

      var myDoc = event.target;

     myDoc.saveAs();

}

catch (e)

{

     xfa.host.messageBox(""+e);

}

try{

7 Replies

Avatar

Level 10

Hi,

Try:

app.execMenuItem("SaveAs");

However myDoc.saveAs() should work as well:

var myDoc = event.target;

myDoc.saveAs();

Maybe move it out of the try statement initially and thne move back in when you have the main statement working.

Good luck,

Niall

Avatar

Level 1

Hi Niall,

The problem is even I remove the try cluase I get the Not Allowed Error as I stated in the question.

I don't know if there is a configuration that I have to do??  I'm now using Acrobat 9 for testing this form but once I deploy it to the server, the users will use Adobe Reader (after extending the PDF to run the scripts and any Web Services).

I'm going to try the below statement and I hope it works.

Mazen

Avatar

Level 10

Hi Mazen,

The app.execMenuItem works here. Is your form designed to be opened in Acrobat/Reader or are you opening the form in html?

Also you may want to consider how you are reader enabling the form. If you are using Acrobat to extend the form, then certain features like database connections will not work.

Lastly, while app.execMenuItem("Close"); will close the form, it will not close/quit Acrobat/Reader.

Good luck,

Niall

Avatar

Level 1

Hi Niall,

The form will be opened by Acrobat/Reader. The statement worked but what I need is to save the PDF in the current location without popping up the Save As dialog box. In other words I would like to perform Ctrl+Saction and then exit the application not only close the form because the Content Management Solution we are using will require the application to be closed so it can CheckIn the document.

I tried to use app.execMenuItem("Save");  but it seems it is not working because once I try to close the application or the form using app.execMenuItem("Close"); the do you want to save changes to "FORM" before closing? dialog box pops-up.

For closing the application I tried app.execMenuItem("Exit"); and I got this error: InvalidArgsError: Invalid arguments.

The customer has Adobe LC Reader Extension so I will use it to extend the PDF but right now I do use Acrobat so I don't need to extend the PDF everytime I need to test it.

Can I get all the arguments that execMenuItem uses?

I really appreciate your help Niall.

PS: I couldn't reply earlier yesterday because my work is on the server and I was at home (my time is +3 GMT it was night when I got your reply)

Regards

Mazen

Avatar

Level 10

Hi Mazen,

Last April Paul exposed the menu items that were available, note that some are restricted due to security issues. See here.

This lead me to develop this form, which gives app.execMenuItem commands and equivalent XFA commands where these are available.

So what this means is that "Save" and "Exit" won't work!!

You can get a "Save" to work, but because it is privileged - you will need a trusted function. There is a long thread here, which goes through the steps (recommend you work through the thread as you can use it for save). However it means that the .js javascript file has to be loaded onto every PC that will be using the form.

As far as I know you cannot close Acrobat/Reader using script - it requires the user to close the application.

Hope this helps,

Niall

ps we are just plain old GMT here ;-)

Avatar

Level 1

Hi Niall,

Sorry for the delay in updating this discussion.

I have gone through the links you passed earlier and tried to checkout a solution but it will not give a good solution for me so I discussed the matter with my team here and we came up with a workaround to overcome the auto save and close the application.

We will prompt the user just to save the file with its default name and location and then close the application.

Now we will use the method to pop-up the SaveAs dialog box.  Is there a way to just fill out the location and file name in the Save As dialog so the user don't have to pick the folder and type the file name (in this case, our work flow will not use the correct form).

I tried the following code:

var myDoc = event.target;

myDoc.saveAs();

and once I clicked on the button I got the following message:

NotAllowedError: Security settings prevent access to this property or method.

Thanks in Advance for your valuable help.

Mazen

Avatar

Level 10

Hi,

As far as I know you cannot specify the folder (save) location without using a trusted function in a folder level javascript file.

I am out of the office, so can't check now. I will have to check if there are changes in overall security policy that now restrict saveAs.

Niall