Page 1 of 1

[javascript] dialog that returns file path

Posted: Thu Aug 01, 2024 7:34 pm
by Mathew
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.

Re: [javascript] dialog that returns file path

Posted: Fri Aug 02, 2024 6:55 pm
by Roman - Tracker Supp
Hi Mathew,
Please see app.browseForDoc.

Re: [javascript] dialog that returns file path

Posted: Fri Aug 02, 2024 9:40 pm
by Mathew
Hi Roman,
Yes, exactly like app.browseForDoc() except that function will only show pdf files.
image.png
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.

Re: [javascript] dialog that returns file path  SOLVED

Posted: Fri Aug 02, 2024 10:18 pm
by Roman - Tracker Supp
You can use something like

Code: Select all

app.browseForDoc({cFilenameInit:"*.myext"})
This will allow to browse for files with .myext extension.

Re: [javascript] dialog that returns file path

Posted: Mon Aug 05, 2024 4:20 pm
by Mathew
Perfect. Thank you for your help.

[javascript] dialog that returns file path

Posted: Mon Aug 05, 2024 8:18 pm
by Daniel - PDF-XChange
:)