Browse button using java script

arunpriyan89483

05-12-2017

Hi,

I trying to create Browse button in PDF form using adobe livecycle designer ES 8.2. Used the below script. With help of this, got the filename only.

var myDoc = event.target;

var sFile = "myFile";

Var a=myDoc.importDataObject({cName: sFile});

var myDataObject = myDoc.getDataObject(a);

var sFileName = myDoc.path;

I want to get the file data which present in attachment and convert that to XML format.

Please help me.

Accepted Solutions (0)

Answers (11)

Answers (11)

Thom_Parker

27-12-2017

A LiveCycle form is really a set of XML sections that define various functional parts of the final live form seen by the user. These sections are also called DOMs.  The two main sections are the form template model and the Data model.  When Acrobat opens an LC form it creates the real form seen by the user by merging the Data block with the form Template.  In JavaScript the "Real Form" is accessed with the "XFA.form" SOM path specifier. The template is accessed with "XFA.template" and the data with "XFA.data". The model used in your script above is defaulted to "XFA.form", because scripts act on the live form model by default, But you can write the script to make persistent changes to the other models.

You can also change the default form settings to force changes to be maintained automatically. Look on "Defaults Tab" of the "Form Properties" dialog. Set the option show in the screen shot below

1381618_pastedImage_2.png

arunap15154166

27-12-2017

Hi Thom,

Scenario: User want to add the new value in drop down list item.

I am creating dynamic drop down list items in adobe LiveCycle designer tool es 8.2 using Custom JavaScript.

Below screenshot is my PDF form

PDF Form.png

User want to add the new values in drop down list -> For this Scenario I have added the button, in click event it will open the popup along text box. Here user, enter the new value in text box and that will added to drop down list items. Up to this all working fine.

Script.PNG

Help

  Added new values in textbox which is temporary stored in drop down list item.  Please advise how to add the new items in

drop down list item permanently using JavaScript. I’m the beginner for this. So please share the demo PDF

Thom_Parker

11-12-2017

The LiveCycle/DB connection is for loading data from the DB into form fields on the LC form.  If this is not the purpose of the XML data, then please explain how the XML is to be used.

Here are a couple of articles that explain submitting by email. One of them provides an LC example.

https://acrobatusers.com/tutorials/dynamically-setting-submit-e-mail-address

https://acrobatusers.com/tutorials/submitting-data

arunpriyan89483

11-12-2017

Thanks Thom.

I want to send the upload/browse file in mail. Could you please share the JavaScript to do this in adobe livecycle designer ES 8.2

Thom_Parker

09-12-2017

Excel is a complex internal format. In fact it's a zip file that contains XML and other data. But the point is that converting Excel data inside the Acrobat JS environment is just not possible. There's no functionality for it.

But since you are using LiveCycle you are in luck!!  You can connect Excel form to ODBC, which the LC form can connect too.

Here's an article on loading data into Acrobat from Excel.

https://www.pdfscripting.com/public/ExcelAndAcrobat.cfm

And it is not true the util.stringFromStream() function only gets data from XML. This function converts the Binary hex encoded data from a stream into ASCII characters. The data and/or file type is irrelevant.

arunpriyan89483

08-12-2017

Hi,

Good day!!

Thanks for your information.

The below two scenarios -I’m trying to upload the excel file in PDF form

First scenarios is

Actually, I have to add/upload the excel file with my PDF form which is created in adobe LiveCycle designer ES8.2. Used the below script to get the data but I able to read the file name only.

var myDoc = event.target;

var sFile = "myFile";

var myDataObject = myDoc.getDataObjectContents(sFile);

var myBudget =util.stringFromStream(myDataObject, "utf-8");

util.stringFromStream - It's only get the data from XML. I want to get data from excel sheet and converted that into XML format. Then I have to add this converted data with my PDF form data in submit click.

Second scenario is

If the above is not possible, then I have to send the upload file in email. I don’t know how to do this.

Please advise me, how solve this issue

_Bruce_Robertson

MVP

06-12-2017

I don't think it would be common for an individual but in many corporate environments you don't have the access to install/upgrade software.

_Bruce_Robertson

MVP

06-12-2017

Probably not a problem but readFileToStream was introduced in Reader 10, so if you have to support older versions it wont work.

There is a getDataObjectContents method which will do what you want and a sample of using it Adobe LiveCycle Designer Cookbooks by BR001: Reading image properties in an Adobe LiveCycle Designer...  .

Regards

Bruce

Thom_Parker

05-12-2017

A better option is to use the util.readFileToStream() function.  Loading data through a file attachment is problematic in Reader and may be an issue in LiveCycle forms.

XML is a native object in the core JS used in Acrobat. Look up E4X.  If you have true XML text then you can simply evaluate it, as long as it does not contain an XML header.

The Acrobat JavaScript model contains an object called XMLData. This is actually the LC xml engine, and is has a function, XMLData.parse().  You can look it up in the Acrobat JS reference here:

Acrobat DC SDK Documentation

The ref only lists two function, but anything returned from the parse function is an XFA object, so all the standard XFA functions apply.