These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

ImportAnFDF() from a specified folder?

David Dunn
Registered: Oct 28 2010
Posts: 116
Answered

Using a MouseUp script attached to a button, I am trying to write a script to open a specific folder from which the user would select an existing fdf file to import.
 
Presumably this would include employing importAnFDF(). Using importAnFDF()with no cPath specified works OK, if you are happy navigating to the correct folder, but that extra step of navigating to the correct folder is what I want to avoid.
 
I can't name a specific file to import in the cPath parameter because the user needs to select the file from among several saved fdf files in the target folder.
 
Also, the path to the folder would be set by the user (i.e., entered in another text field that will remain saved & unchanged from customer to customer), and therefore I want to accomplish this using a variable to identify the text field holding the cPath.
 
Here is what I tried unsuccessfully:
 
/*variable 'agents' identifies the field holding the cPath I want to access. For sake of discussion the path is /C/1Data/1MDF_AgentsSellers */
 
var agents = this.getField("txt.P1.Path.Database.SellerAgents").value
 
this.importAnFDF(+agents + "/*.fdf")

David D

My Product Information:
Acrobat Pro 9.4, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
If you do not know the exact name and location of the FDF file then the best that can be done is to call

this.importAnFDF();

with no parameters. The path and name cannot be specified separately. The user has to manually browse the file system to find the input file. And if you did know the exact name and location, this code could not be run from inside a document script. File system operations in Acrobat JavaScript are privileged, they require a trusted context.

Also, it looks like your code is written for a LiveCycle form SOM path? If this is a LiveCycle form an FDF file won't do you much good, you'll need to use an XDP or XML file. There is an import function in the XFA scripting reference that will need to be used.

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

David Dunn
Registered: Oct 28 2010
Posts: 116
Thank you Tom for your input. I discovered before sending my inquiry that importAnFDF() is one of the few methods I've found that will take a path and return without privilege. If you know the path and file name and set it between the ("") (e.g. importAnFDF("/c/1Data/myDoc.fdf") by example)it will import that file from a Mouse up document JavaScript. This action alerts me first that I should trust the source, but gives me the option to proceed with the import and then imports the data when I click on "allow."

The code in my example is written for an Acrobat pdf. I have not yet learned anything significant about LiveCycle.

DavidD

David D

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Accepted Answer
You are correct. I didn't look in the reference before answering, my apologies. It's odd that this and the importAnXFDF are the only import functions that are not privileged.

But the sad fact is that there is no way to preset either the file name or the initial folder path:-(

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

David Dunn
Registered: Oct 28 2010
Posts: 116
Thanks Thom. Yes it is odd. I was pretty excited when I discovered it, only to be disappointed in the result. "Sad" is an accurate observation.

I understand the need for security, but it seems to this novice that Adobe creates a lot of roadblocks to automation with privileged status, but I suppose there are good reasons of which I am unaware. One of my fondest wishes though is that Adobe would allow a form creator to enable a lot more Reader capability than presently allowed. It just seems to me that doing so would only increase demand for Acrobat pdf forms, thus increasing demand for the work of developers and ultimately Acrobat. But I digress. Thanks again!

DavidD

David D