Search code examples
javascriptacrobat

Opening pdf using Acrobat Javascript on Apple


I would like to open a pdf document using Javascript in Acrobat Pro DC running OSX. Here's what I see:

app.openDoc("~/Desktop/test.pdf")
Invalid Location "~/Desktop/test.pdf". File or folder does not exist.
NotAllowedError: Security settings prevent access to this property or method.
App.openDoc:1:Console undefined:Exec
undefined

I wonder whether the error is the security restrictions mentioned on page 135 of the Javascript for Acrobat reference.


Solution

  • Because Acrobat JavaScript is cross-platform, you need to use device independent paths and you can't use device-specific shortcuts like "~". Something like the examples below.

    Windows Path C:\MyFolder\MyFile.pdf

    app.openDoc("/C/MyFolder/MyFile.pdf");
    

    Macintosh path MyDisk:MyFolder:MyFile.pdf

    app.openDoc("/MyDisk/MyFolder/MyFile.pdf");
    

    You can use "../" for relative paths.