Skip to main content
tpk1982
Legend
October 25, 2016
Question

saveAs in Mac

  • October 25, 2016
  • 18 replies
  • 1602 views

HI,

I am trying to saveAs the opened pdf in my server. Before the sever address i tried to save the file in desktop but it is not working. Could you please suggest me?

this.saveAs("/Macintosh HD/Users/kk/Desktop/xxxxx.pdf");

app.closeDoc();

another method:

this.saveAs("~/\Desktop/\/xxxxx.pdf");

app.closeDoc();

I read this articles but not able to solve

https://acrobatusers.com/tutorials/how-save-pdf-acrobat-javascript

https://acrobatusers.com/tutorials/file-paths-acrobat-javascript

Thanks,

K

This topic has been closed for replies.

18 replies

Legend
October 26, 2016

I think you may be using the console the wrong way. ENTER only runs the current line, unless you select the text first.

You you can put a function call on a button but the function definition must be in a startup script. This is a vital security protection. I suggest too that you use an entirely unique name for the script, never copy the name of a model.

Karl Heinz  Kremer
Community Expert
Community Expert
October 25, 2016

When you use a Unix style path on a Mac, the "Macintosh HD" portion of the path is not used. Try using this:

    this.saveAs("/Users/kk/Desktop/xxxxx.pdf");

Keep in mind that you need to do this from within a privileged context (see here for more information: Acrobat DC SDK Documentation - Doc.saveAs()

tpk1982
tpk1982Author
Legend
October 26, 2016

Hi try67,

When i try to run in console it shows error like below

@Karl: I tried with this.saveAs("/Users/kk/Desktop/xxxxx.pdf"); but same error occurs

Regards,

K

try67
Community Expert
Community Expert
October 25, 2016

What happens when you run this code? Also, from where are you running it?

And app.closeDoc(); is not a valid command. the closeDoc method is a part of the Document object. Use this instead:

this.closeDoc();

If you want to know the correct syntax for the file-path of a specific file, open it in Acrobat and then execute this code in the JS Console:

this.path;

It will print out the full path of current file, in the syntax that you need to use in your code.

tpk1982
tpk1982Author
Legend
October 25, 2016

Hi try67,

Thanks for your reply. Nothing happen. I am using this script with SUBMIT button. While i am pressing i need to save a copy of file to specific path.

Yes i tried the app.alert(this.path) method to know the location and used the same in the code (

  1. this.saveAs("/Macintosh HD/Users/kk/Desktop/xxxxx.pdf"); 

)

Thanks,

Karthi

try67
Community Expert
Community Expert
October 25, 2016

You can't use this command from a button just like that. It needs to run from a trusted context, e.g. a folder-level script.

If you check the JS Console (Cmd+J) you'll see an error message there saying that the method failed for security reasons.