[javascript] dialog that returns file path  SOLVED

Please post any ideas or requests for new features here for the End User Version of PDF-XChange (printer Drivers)

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

Post Reply
Mathew
User
Posts: 564
Joined: Thu Jun 19, 2014 7:30 pm

[javascript] dialog that returns file path

Post 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.
User avatar
Roman - Tracker Supp
Site Admin
Posts: 331
Joined: Sun Nov 21, 2004 3:19 pm

Re: [javascript] dialog that returns file path

Post by Roman - Tracker Supp »

Hi Mathew,
Please see app.browseForDoc.
Mathew
User
Posts: 564
Joined: Thu Jun 19, 2014 7:30 pm

Re: [javascript] dialog that returns file path

Post by Mathew »

Hi Roman,
Yes, exactly like app.browseForDoc() except that function will only show pdf files.
image.png
image.png (6.28 KiB) Viewed 4389 times
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.
User avatar
Roman - Tracker Supp
Site Admin
Posts: 331
Joined: Sun Nov 21, 2004 3:19 pm

Re: [javascript] dialog that returns file path  SOLVED

Post 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.
Mathew
User
Posts: 564
Joined: Thu Jun 19, 2014 7:30 pm

Re: [javascript] dialog that returns file path

Post by Mathew »

Perfect. Thank you for your help.
User avatar
Daniel - PDF-XChange
Site Admin
Posts: 10904
Joined: Wed Jan 03, 2018 6:52 pm

[javascript] dialog that returns file path

Post by Daniel - PDF-XChange »

:)
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
Post Reply