codevour codevour - 23 days ago 8
Javascript Question

Acrobat Javascript Save & Exit Button

I have a writeable pdf form created in acrobat pro. Now, i added a button which has to change a fields value, save the pdf and close it.

I decided to do this as following:

var fieldX = this.getField("xxxxField");
fieldX.value = 1;
app.execMenuItem("Save");
this.closeDoc(true);


But this doesn't save the pdf.

I don't want to have a confirmation dialog. I saw the
saveAs
function in the API but how to get the real-path incl. filename of the current editing document? Or do you have any other approaches?

thank you.

Answer

But this doesn't save the pdf.

That's because there are security restrictions that prevent app.execMenuItem("Save"); from working. You're not allowed to call Save via JS.

function in the API but how to get the real-path incl. filename of the current editing document? Or do you have any other approaches?

You can use Doc.path to get the path of the current document including its filename (and Doc.documentFilename gives you the filename only).

However, saveAs is also subject to security restrictions, and it can only be called in a "privileged" context (batch or console). So this won't work either.

In short, security restrictions will prevent you from saving documents without asking the user. If you think about it, it's only logical.

See: Acrobat JS API Reference

Comments