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

importDataObject

krm240
Registered: Apr 17 2009
Posts: 95

I am trying to get importDataObject to import a text file and then parse the text stream to populate a drop down list.

(all code is being run in the console, I am using Adobe 9 Pro and LC2 Designer)
I am able to get the following to work perfectly
createDataObject("MyData.txt", "TXT\r\nDAT\r\nDOC\r\nDOCX");

But the following code (importing from a txt file) I have a problem with:
importDataObject("MyDataI.txt", "/c/temp/Test7.txt");
The txt file data file looks like this:
"TXT\r\nDAT\r\nDOC\r\nDOCX" // Same as the text stream using createDataObject
*******
Both file data get attached to the pdf checked with:
// list data objects
console.println("\nList of data objects:");
var d = dataObjects;
for (var i = 0; i < d.length; i++)
console.println("Data Object[" + i + "]=" + d[i].name);

List of data objects:
Data Object[0]=MyData.txt
Data Object[1]=MyDataI.txt
***********
When I list the contents I see both files but in different formats
using:
var oPropertyName = "MyDataI.txt"; // Change name to MyData.txt or MyDataI.txt
console.println("\nContents of data object: " + oPropertyName );
var oFile = getDataObjectContents(oPropertyName);
// convert to a string & print
var sContents = util.stringFromStream(oFile, "utf-8");
console.println("Length of contents: " + sContents.length);
console.println(sContents);

console.println("\nArray element contents " + oPropertyName);
var aContents = sContents.split("\r\n");
console.println("Number of arrays: " + aContents.length);
for (i = 0; i < aContents.length; i++)
console.println(i + ": " + aContents[i]);

Contents of data object: MyDataI.txt
Length of contents: 28
"TXT\r\nDAT\r\nDOC\r\nDOCX"

Array element contents MyDataI.txt
Number of arrays: 1
0: "TXT\r\nDAT\r\nDOC\r\nDOCX"

Contents of data object: MyData.txt
Length of contents: 19
TXT
DAT
DOC
DOCX

Array element contents MyData.txt
Number of arrays: 4
0: TXT
1: DAT
2: DOC
3: DOCX

****************
Questions:
Why does the output data look different when reading the actual txt file?
When using LC2, and trying to import a text file, (to parse the text stream and pre load a drop down), is this the best function to use? I really do not want to use dynamic linking as do not want to deal with ODBC connect strings for this function.
What functions are available to LC2 designer for the importing of data as a text stream?

My Product Information:
LiveCycle Designer, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Importing data objects is a pain. And as you experienced there are some variations in behavior that cannot be controlled from JavaScript. However, since you are using a LiveCycle form, you have the option to use dynamic binding from a connection to an XML file. Of course the user has to load the XML file. But as soon as it's loaded all fields, and lists, will be updated. No scripting necessary.


Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

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