Scope: All Acrobat versions
Skill Level: Intermediate
In Acrobat 7.0, Adobe added a new function to the App Object, app.browseForDoc(). This function displays the standard platform file dialog. This is the same dialog used for opening and saving files in all of your applications. The operating system creates and manages this dialog. Acrobat simply hands off a set of operating parameters to the operating system and makes a request to display it.
Acrobat restricts the file types accessible with the dialog to those with a “.pdf” extension, so the dialog is only good for finding PDF files. A few other dialog characteristics are controlled by the input arguments. The full argument listing is shown here:app.browseForDoc(bSave,
// File Save Dialog app.browseForDoc(true); // File Open Dialog, same as default behavior app.browseForDoc(false);
The second argument, cFilenameInit, is the initial file name placed in the dialog. If the “.pdf” file extension is missing, Acrobat automatically adds the extension. If another file extension is used, Acrobat strips this off and replaces it with “.pdf.” This argument cannot be used to set the initial directory, only the file name. The file browser opens in Acrobat’s current directory. Run the following code from the console and see what happens.
The final argument, cFSInit, defines the file system where the dialog will be used. An empty string (the default) indicates the local file system. A value of “CHTTP” indicates the file name can be retrieved from a WebDAV server. This does not stop the user from selecting a local file. When this argument is set, the user can browse both the local file system and WebDAV.
var oRtn = app.browseForDoc(); // File system name var myFileSystem = oRtn.; // File Path var myFilePath = oRtn.cPath; // File URL var myFileURL = oRtn.cURL;
Typical file system names returned in the cFS property are “CHHTP”, “DOS”, and “MacOSX.” However, unless you need to tell the difference between a WebDAV path and a local file path, these names are unimportant. Both the cPath and cURL parameters are filled in no matter which file system is used. The only difference between them is the path format. The cPath parameter uses Acrobat Device Independent format. Two examples are shown below.
// Mac OSX oRtn.cPath = "/osx/Users/me/Desktop/Sample.pdf"; // Windows oRtn.cPath = "/c/Document and Settings/me/Desktop/Sample.pdf";
The cURL parameter uses the standard URI format. Two examples are shown below.
//Local File System file oRtn.cURL = "file://localhost/Users/me/Desktop/Sample.pdf"; //WebDAV server oRtn.cURL = "http://www.myDocs.com/comments/Sample.pdf";
Typically, the cURL parameter is used for a WebDAV file system and the cPath parameter is used for a local file path
Please see the example file below for a working Folder Level script.
Document Browser Example file
Download [PDF, 24 KB]
One final note, the app.browseForDoc(), function is privileged. In short, this means for security reasons it cannot be executed from a document script, or at least not directly. Its main use is in Folder Level (application level) automation scripts. This limitation doesn’t completely kill it’s usefulness in document applications; it just makes things more difficult.
|Edit PDF create PDF Action Wizard|
Try Acrobat DC
Get started >
Post, discuss and be part of the Acrobat community.
Join now >