Help with getting values out of custom dialog

New Here ,
Mar 20, 2018 Mar 20, 2018

Copy link to clipboard

Copied

Here is my situation.

I have created a custom tool button which when pressed will acitvate the dialog.

When the info has been entered and the dialog is closed the values saved in the dialog will be written our in a free text annotation.

I can create the button.

I have created the dialog.

I can print out the stored values to the console so I know everything is working as it should be.

Now where I am stuck is getting those values to the annotation. I have been reading all the documentation but can't make anything work.

If someone could please point me in the right direction on how to access stored variables in the dialog object I would greatly appreciate.

The code itself works fine. It's just the skeleton right now. I will beef it up later.  just can't figure out how to pass the values to the annotation function. I have tried putting the annotation inside the commit method but that just gave me an error saying it wasn't a function so I tried moving it outside which is where my code stands now.

Everything can be run from the javascript console.

Thanks in advance for any help you can give.

Here is my code for the dialog object. and annotation.var TestDlg1 =

{

initialize: function(dialog)

{

   

// set a default value for radio groups

dialog.load(

{

"rad1": true,

"rad4": true,

"rad7": true

});

this.hasfta = false;

// disable the fta case# field

dialog.enable(

{

"fta1" : this.hasfta

});

},

rad7: function (dialog) {

// Process the fta, if the user selects yes enable the fta case# field

this.hasfta = !this.hasfta;

dialog.enable({

"fta1" : this.hasfta

});

},

commit:function (dialog) { // called when OK pressed

var results = dialog.store();

// check to see if variables are stored

//console.println("DD1 is " + results["ddt1"] + "and the diary date remarks are " + results["ddr1"])

//console.println("DD2 is " + results["ddt2"] + "and the diary date remarks are " + results["ddr2"] );

var mytext = results["ddt1"];  // try to assign the variables to access outside the dialog

var mytext2 = results["ddr1"];

},

// build my dialog

description:

{

name: "Test Dialog",

elements:

[

{

type: "view",

align_children: "align_left",

elements:

[

{

type: "cluster",

name: "DIARY DATES",

elements:

[

{

type: "view",

align_children: "align_row",

elements:

[

{

type: "static_text",

name: "DD1",

bold: true,

font: "dialog",

},

{

item_id: "ddt1",

type: "edit_text",

char_width: 20,

height: 20,

width: 80

},

{

type: "static_text",

name: "DDR1",

bold: true,

font: "dialog",

},

{

item_id: "ddr1",

type: "edit_text",

alignment: "align_fill",

width: 200,

height: 20

},

{

type: "static_text",

name: "case#",

bold: true,

font: "dialog",

},

{

item_id: "cse1",

type: "edit_text",

alignment: "align_fill",

width: 200,

height: 20

},

]

},

{

type: "view",

align_children: "align_row",

elements:

[

{

type: "static_text",

name: "DD2",

bold: true,

font: "dialog",

},

{

item_id: "ddt2",

type: "edit_text",

char_width: 20,

height: 20,

width: 80

},

{

type: "static_text",

name: "DDR2",

bold: true,

font: "dialog",

},

{

item_id: "ddr2",

type: "edit_text",

alignment: "align_fill",

width: 200,

height: 20

},

{

type: "static_text",

name: "case#",

bold: true,

font: "dialog",

},

{

item_id: "cse2",

type: "edit_text",

alignment: "align_fill",

width: 200,

height: 20

},

]

},

{

type: "view",

align_children: "align_row",

elements:

[

{

type: "static_text",

name: "DD3",

bold: true,

font: "dialog",

},

{

item_id: "ddt3",

type: "edit_text",

char_width: 20,

height: 20,

width: 80

},

{

type: "static_text",

name: "DDR3",

bold: true,

font: "dialog",

},

{

item_id: "ddr3",

type: "edit_text",

alignment: "align_fill",

width: 200,

height: 20

},

{

type: "static_text",

name: "case#",

bold: true,

font: "dialog",

},

{

item_id: "cse3",

type: "edit_text",

alignment: "align_fill",

width: 200,

height: 20

},

]

},

]

},

{

type:"view",

alignment: "align_left",

align_children: "align_row",

elements:

[

{

type: "cluster",

alignment: "align_left",

name: "ADD FTA?",

align_children: "align_left",

elements:

[

{

type: "radio",

name: "NO",

bold: true,

font: "dialog",

item_id: "rad7",

group_id: "ddrd"

},

{

type: "view",

allignment: "align_left",

align_children: "align_row",

elements:

[

{

type: "radio",

name: "YES",

bold: true,

font: "dialog",

item_id: "rad7",

group_id: "ddrd"

},

{

type: "static_text",

name: "FTA Case#",

bold: true,

font: "dialog"

},

{

type: "edit_text",

item_id: "fta1",

alignment: "align_fill",

width: 200,

height: 20

},

]

},

]

},

{

type: "view",

width: 300,

alignment: "align_left",

align_children: "align_left",

elements:

[

{

type: "ok_cancel",

}

]

},

]

},

]

},

{

type: "view",

align_children: "align_left",

elements:

[

{

type: "cluster",

name: "DL",

elements:

[

{

type: "radio",

item_id: "rad1",

group_id: "dlrd",

name: "NO DL"

},

{

type: "radio",

item_id: "rad2",

group_id: "dlrd",

name: "ADD DL"

},

{

type: "radio",

item_id: "rad3",

group_id: "dlrd",

name: "VALID DL"

},

]

},

{

type: "cluster",

name: "PNTRV",

elements:

[

{

type: "radio",

item_id: "rad4",

group_id: "pvrd",

name: "NO PNTRV"

},

{

type: "radio",

item_id: "rad5",

group_id: "pvrd",

name: "ADD PNTRV"

},

{

type: "radio",

item_id: "rad6",

group_id: "pvrd",

name: "PNTRV VALID"

},

]

}

]

},

]

}

};

//app.execDialog(TestDlg1); this was just for initial testing

if ("ok" == app.execDialog(TestDlg1))

{

// var mytext = results["ddt1"]

// var mytext2 = results["ddr1"]

var mytext3 = "2013-08-25"

var mytext4 = "AGED WARRANT REVIEW"

var mytext5;

var spans = new Array();

spans[0] = new Object();

spans[0].textStyle = "bold";

spans[0].textColor = color.blue;

spans[0].textSize = 10;

spans[0].fontFamily = ["Arial Black", "monospace" ];

// spans[0].text = mytext+"\r" + mytext2+"\r\r"+mytext5+"\r"+mytext; <<<this didn't work

// spans[0].text = TestDlg1.mytext+"\r"+ TestDlg1.mytext2+"\r\r"+mytext5+"\r"+mytext; <<<<this didn't work

// spans[0].text = results["ddt1"] +"\r"+ results["ddr1"] +"\r\r"+mytext5+"\r"+mytext; // this didn't work

spans[1] = new Object();

spans[1].text = "DD1: "+mytext3+"\r"+mytext4;

spans[1].textColor = color.blue;

spans[1].textSize = 20;

spans[1].alignment = "left";

if(mytext5 == ""){ //testing to see if the if statement works

spans[2] = new Object();

spans[2].text = "will soon be here!";

spans[2].textColor = color.green;

spans[2].fontStyle = "italic";

spans[2].underline = true;

spans[2].alignment = "right";

}

// Now create the annot with spans as it's richContents

var annot = this.addAnnot({

page: 0,

type: "FreeText",

rect: [50, 50, 300, 300],

richContents: spans

});

}

Message was edited by: demian seiden code formatting was all messed up in my original post. No indents now but it is much more readable.

TOPICS
Acrobat SDK and JavaScript

Views

273

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct Answer

Adobe Community Professional , Mar 20, 2018 Mar 20, 2018
There are a several different ways to do this. The method I prefer is to add a property to the dialog definition object for each field value that will be exported, then assign these values in the commit function. You'll find pretty much everything you need to create dialogs here, including a drag and drop dialog designer for Acrobat JavaScript:Alerts, Popups, and Other Devices for Interacting with the User

Likes

Translate

Translate
Adobe Community Professional ,
Mar 20, 2018 Mar 20, 2018

Copy link to clipboard

Copied

There are a several different ways to do this. The method I prefer is to add a property to the dialog definition object for each field value that will be exported, then assign these values in the commit function.

You'll find pretty much everything you need to create dialogs here, including a drag and drop dialog designer for Acrobat JavaScript:

Alerts, Popups, and Other Devices for Interacting with the User

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 20, 2018 Mar 20, 2018

Copy link to clipboard

Copied

Hi Thom, thanks for the reply. I actually have your book on stamps. That's what got me started down this road in the first place. This dialog is my attempt to replace 4 separate dynamic stamps I have created and currently use. I looked at your acrodialog tool as well. It looks amazing but I like to try to do things on my own. I enjoy the challenge. I have been pretty successful so far, up until this point at least. I have toyed with the idea of joining your site for a while now but just never pulled the trigger yet. I probably will at some point soon.

Ok so if I understand you correctly I assign my values in the commit function. So I tried this. (I'm not reposting all my code cause it is so long.)

commit:function (dialog) { // called when OK pressed

var results = dialog.store();

// check to see if variables are stored

console.println("DD1 is " + results.ddt1 + " and the diary date remarks are " + results["ddr1"] );

console.println("DD2 is " + results.ddt2 + " and the diary date remarks are " + results["ddr2"] );

console.println("DD3 is " + results.ddt3 + " and the diary date remarks are " + results["ddr3"] );

//the above works so I know the values are getting stored.

  // try to assign the variables to access outside the dialog

var mytext2 = results["ddr1"]; // <<<did not work

getdiarydate1: function(results){

var mytext = results["ddt1"];

return mytext;

};

getdiarydate2: function(results){

var mytext2 = results["ddr1"];

return mytext2;

};

// the function definitions above also did not work

If you could show me an exact example of what you mean I would greatly appreciate it. 🙂

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 21, 2018 Mar 21, 2018

Copy link to clipboard

Copied

Ha, never mind, I finally got it working. With a little help from your tutorial. I wasn't using the correct syntax when accessing the variable. I knew it must be something obvious, but I don't think I would have figured it out on my own. Now I just have to make full use of my membership 🙂

Thanks for the advice Thom. You may be hearing a lot more from me in the future. @

Code below if anyone is interested.

var TestDlg1 =

{

cDd1:"",

cDd2:"",

cDd3:"",

cDdr1:"",

cDdr2:"",

cDdr3:"",

cDdcase1:"",

cDdcase2:"",

cDdcase3:"",

initialize: function(dialog){

//blah blah blah

},

commit:function(dialog)

{ // called when OK pressed

var results = dialog.store();

// assign the variables to access outside the dialog

this.cDd1 = results.ddt1;

this.cDd2 = results.ddt2;

this.cDd3 = results.ddt3;

this.cDdr1 = results.ddr1;

this.cDdr2 = results.ddr2;

this.cDdr3 = results.ddr3;

this.cDdcase1 = results.cse1;

this.cDdcase2 = results.cse2;

this.cDdcase3 = results.cse3;

},

// build my dialog

description:

{

// my dialog in here.

}

if ("ok" == app.execDialog(TestDlg1))

{

var spans = new Array();

spans[0] = new Object();

spans[0].textStyle = "bold";

spans[0].textColor = color.blue;

spans[0].textSize = 10;

spans[0].fontFamily = ["Arial Black", "monospace" ];

spans[0].text = TestDlg1.cDd1+"\r"+TestDlg1.cDd2+"\r" + TestDlg1.cDd3;

}

//SUCCESS

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Mar 21, 2018 Mar 21, 2018

Copy link to clipboard

Copied

LATEST

Excellent! Glad you got it figured out. It's always a nice feeling when you've been working on something for a while and get it worked out. 

In JavaScript, the relationships between things are not always obvious, until you develop a good understanding of how JS objects work. In this case the Dialog Definition object is just a regular generic JS object. You can put anything in it that you want. The execDialog() only operates on the bits it cares about and ignores everything else. The other important bit is that from within an object, any object, the keyword "this" refers to the object itself, and is required for accessing members of the object.

Good Luck,

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines