I'm looking for a way to present a user with a dialog box to select a file, and get the path to the selected file.
The method util.readFileIntoStream() takes a parameter cDIPath to the file that is to be read. The API says that if cDIPath is not specified, then a dialog to select the file is presented (this part currently doesn't work in PXE). However, either way, it returns the content. I don't see any way to open a dialog for the user to select a file, and then get the path to that file so it can be saved for later?
tl;dr
The only functionality I can find is for a text field with fileSelect = true and browseForFileToSubmit() on that field. However, it's not possible to create such a field on the fly within javascript except if run from the console. (I've tried a trusted function but assigning field.fileSelect = true fails.)
I can save a simple pdf document with only a fileSelect field, open that document, and run browseForFileToSubmit() on that field (it pops up a security alert for opening that pdf though). But this workaround seems awfully clumsy.
What's needed is a util.browseForFile() method that returns a device independent path.
[javascript] dialog that returns file path SOLVED
Moderators: Daniel - PDF-XChange, PDF-XChange Support, Vasyl - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange, Tracker - Clarion Support, John - Tracker Supp, Support Staff, moderators
- Roman - Tracker Supp
- Site Admin
- Posts: 331
- Joined: Sun Nov 21, 2004 3:19 pm
Re: [javascript] dialog that returns file path
Hi Mathew,
Please see app.browseForDoc.
Please see app.browseForDoc.
Re: [javascript] dialog that returns file path
Hi Roman,
Yes, exactly like app.browseForDoc() except that function will only show pdf files. I need it to select a text file (with a different suffix, not .txt) so that for example the hatch pattern tool can select different hatch patterns to load, or a custom linetype tool can select linetypes. Currently one needs to edit the javascript file directly, but if there were a method that allowed one to browse for arbitrary files then that could easily be part of a script.
- Mathew.
Yes, exactly like app.browseForDoc() except that function will only show pdf files. I need it to select a text file (with a different suffix, not .txt) so that for example the hatch pattern tool can select different hatch patterns to load, or a custom linetype tool can select linetypes. Currently one needs to edit the javascript file directly, but if there were a method that allowed one to browse for arbitrary files then that could easily be part of a script.
- Mathew.
- Roman - Tracker Supp
- Site Admin
- Posts: 331
- Joined: Sun Nov 21, 2004 3:19 pm
Re: [javascript] dialog that returns file path SOLVED
You can use something like
This will allow to browse for files with .myext extension.
Code: Select all
app.browseForDoc({cFilenameInit:"*.myext"})
Re: [javascript] dialog that returns file path
Perfect. Thank you for your help.
- Daniel - PDF-XChange
- Site Admin
- Posts: 10904
- Joined: Wed Jan 03, 2018 6:52 pm
[javascript] dialog that returns file path

Dan McIntyre - Support Technician
PDF-XChange Co. LTD
+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
PDF-XChange Co. LTD
+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com