Code for a Complex Acrobat JavaScript Dialog

This screenshot shows a complex dialog executed in Acrobat. Scroll down to see the code required to generate this dialog.

 

Below is the code auto-generated by AcroDialogs for the dialog shown above.  This exemplifies the time, effort and costs that can be saved using AcroDialogs over hand coding these dialogs with Acrobat JavaScript.

//Acrobat JavaScript Dialog
//Created by DialogDesigner from WindJack Solutions
//<CodeAbove>
var sizeList =
[
{name:"Letter",w:612,h:792},
{name:"Legal",w:612,h:1008},
{name:"Executive",w:522,h:756},
{name:"A0",w:2384,h:2835},
{name:"A1",w:1684,h:2384},
{name:"A2",w:1190,h:1684},
{name:"A3",w:842,h:1190},
{name:"A4",w:595,h:842},
{name:"A5",w:420,h:595},
{name:"A6",w:298,h:420},
{name:"A7",w:209,h:298},
{name:"B0",w:2384,h:4008},
{name:"B1",w:2004,h:2835},
{name:"B2",w:1417,h:2004},
{name:"B3",w:1001,h:1417},
{name:"B4",w:709,h:1001},
{name:"B5",w:499,h:709},
{name:"B6",w:354,h:499},
{name:"B7",w:249,h:354},
{name:"B8",w:176,h:249},
{name:"B9",w:125,h:176},
{name:"B10",w:88,h:125},
{name:"C2",w:1837,h:1298},
{name:"C3",w:919,h:578},
{name:"C4",w:919,h:649},
{name:"C5",w:649,h:459},
{name:"C6",w:459,h:323}
];

var imgDisplay;
var m_bLastMult = 1;
//</CodeAbove>
var TileDlg =
{
result:"cancel",
DoDialog: function(){return app.execDialog(this);},
strpsiz:["Letter"],
strShtHeight:"",
strShtWdth:"",
strUnits:"Rad1",
strRows:["1"],
strCols:["1"],
strSep:"18",
strTopMarg:"36",
strLeftMarg:"36",
strRightMarg:"36",
strBotMarg:"36",
GetRadioSel:function(oRslts,aCtrls){
for(var strRtn=aCtrls[0];aCtrls.length>0;strRtn=aCtrls.pop()){
if(oRslts[strRtn] == true)
return strRtn;
}
return "";
},
SetListSel:function(list,path){if(path.length == 0) return;
eval("list[\""+ ((typeof path.join != "function")?path:path.join("\"][\"")) + "\"] = 1")},
GetListSel:function(oLstRslts,path){
for(var item in oLstRslts){
if( ((typeof oLstRslts[item]=="number")&&(oLstRslts[item]>0)){
|| this.GetListSel(oLstRslts[item],path) )
{path.push(item);return true;}
}
return false;
},
wdthSheet:0,
hghtSheet:0,
wdthTile:0,
hghtTile:0,
sepDim:0,
mrgTop:0,
mrgLeft:0,
mrgRight:0,
mrgBottom:0,
wdthPage:200,
hghtPage:150,
nRows:1,
nCols:1,
initialize: function(dialog)
{
var listpsiz =
{
"Custom": -1,
"Letter": -1,
"Legal": -2,
"Executive": -3,
"A0": -2,
"A1": -3,
"A2": -4,
"A3": -5,
"A4": -6,
"A5": -7,
"A6": -8,
"A7": -9,
"B0": -9,
"B1": -9,
"B2": -9,
"B3": -9,
"B4": -9,
"B5": -9,
"B6": -9,
"B7": -9,
"B8": -1,
"B9": -1,
"B10": -1,
"C2": -1,
"C3": -1,
"C4": -1,
"C5": -1,
"C6": -1,
};
this.SetListSel(listpsiz, this.strpsiz);

var listRows =
{
"1": -1,
"2": -1,
"3": -1,
"4": -1,
"5": -1,
"6": -1,
};
this.SetListSel(listRows, this.strRows);

var listCols =
{
"1": -1,
"2": -1,
"3": -1,
"4": -1,
"5": -1,
"6": -1,
};
this.SetListSel(listCols, this.strCols);

var dlgInit =
{
"psiz": listpsiz,
"Rows": listRows,
"Cols": listCols,
"Sepr": this.strSep,
"TMrg": this.strTopMarg,
"LMrg": this.strLeftMarg,
"RMrg": this.strRightMarg,
"BMrg": this.strBotMarg,
"hght": this.strShtHeight,
"wdth": this.strShtWdth,
};
dlgInit[this.strUnits] = true;
dialog.load(dlgInit);
dialog.enable(
{
"wdth": false,
"hght": false,
}
);
this["psiz"](dialog);
},
commit: function(dialog)
{
var oRslt = dialog.store();
var path = new Array();
this.strpsiz = (this.GetListSel(oRslt["psiz"],path))?path.reverse():"";
this.strShtHeight = oRslt["hght"];
this.strShtWdth = oRslt["wdth"];
this.strUnits = this.GetRadioSel(oRslt,["Rad1","Rad2","Rad3"]);
var path = new Array();
this.strRows = (this.GetListSel(oRslt["Rows"],path))?path.reverse():"";
var path = new Array();
this.strCols = (this.GetListSel(oRslt["Cols"],path))?path.reverse():"";
this.strSep = oRslt["Sepr"];
this.strTopMarg = oRslt["TMrg"];
this.strLeftMarg = oRslt["LMrg"];
this.strRightMarg = oRslt["RMrg"];
this.strBotMarg = oRslt["BMrg"];
},
"BMrg": function(dialog)
{
this["psiz"](dialog);
},
"RMrg": function(dialog)
{
this["psiz"](dialog);
},
"LMrg": function(dialog)
{
this["psiz"](dialog);
},
"TMrg": function(dialog)
{
this["psiz"](dialog);
},
"Rfsh": function(dialog)
{
function InBox(nX,nY)
{
return ((nX == 10) || (nX == 40)) && (nY == 20);
}
var wdthDspl = 100;
var hghtDspl = (this.hghtSheet * wdthDspl)/this.wdthSheet;
if(hghtDspl > 125)
{
hghtDspl = 125;
wdthDspl = (this.wdthSheet * hghtDspl)/this.hghtSheet;
}
hghtDspl = Math.floor(hghtDspl);
wdthDspl = Math.floor(wdthDspl);
var nScale = hghtDspl/this.hghtSheet;
imgDisplay = {"width": wdthDspl,"height": hghtDspl, offset: 0,
"read": function(bytes){return this.imgstr.slice(this.offset,this.offset+=bytes);}};
var topMrg = Math.floor(this.mrgTop * nScale);
var lftMrg = Math.floor(this.mrgLeft * nScale);
var sep = Math.floor(this.sepDim * nScale);
var Wtile = Math.floor(this.wdthTile * nScale);
var Htile = Math.floor(this.hghtTile * nScale);

var xMin = lftMrg;
var xMax = lftMrg + Wtile;
var yMin = topMrg;
var yMax = topMrg + Htile;

var nHcnt = 0, nVcnt=0;
imgDisplay.imgstr = new String();
var nPos = 0;
var bOn = true;
for(var nY=0;nY<hghtDspl;nY++)
{
//console.println("Row " + nY);
xMin = lftMrg;
xMax = lftMrg + Wtile;
nHcnt = 0;
for(var nX=0;nX<wdthDspl;nX++)
{
if( ((nX==xMin)||(nX==xMax))&&(nY>=yMin)&&(nY<=yMax)
|| ((nY==yMin)||(nY==yMax))&&(nX>=xMin)&&(nX<=xMax) )
imgDisplay.imgstr += "FFFF0000";
else
imgDisplay.imgstr += "FFFFFFFF";
if(nX>xMax)
{
nHcnt++;
if(nHcnt < this.nCols)
{
xMin += Wtile + sep;
xMax = xMin + Wtile;
}
}
}
if(nY>yMax)
{
nVcnt++;
if(nVcnt<this.nRows)
{
yMin += Htile + sep;
yMax = yMin + Htile;
}
}
}
dialog.enable({"img1":false});
dialog.load({"img1":imgDisplay});
dialog.enable({"img1":true});
},
"Sepr": function(dialog)
{
this["psiz"](dialog);
},
"Cols": function(dialog)
{
this["psiz"](dialog);
},
"Rows": function(dialog)
{
this["psiz"](dialog);
},
"Rad3": function(dialog)
{
this["psiz"](dialog);
},
"Rad2": function(dialog)
{
this["psiz"](dialog);
},
"Rad1": function(dialog)
{
this["psiz"](dialog);
},
"wdth": function(dialog)
{
this["psiz"](dialog);
},
"hght": function(dialog)
{
this["psiz"](dialog);
},
"psiz": function(dialog)
{
var rslts = dialog.store();
var sel ="";
for(var entry in rslts["psiz"])
{
if(rslts["psiz"][entry] >= 0)
{
sel = entry;
break;
}
}

var mult = 1;
var strUnits = "pts"
if(rslts["Rad2"])
{
strUnits = "in"
mult = 72;
}
else if(rslts["Rad3"])
{
strUnits = "mm"
mult = 2.835;
}

var bCustom = (sel =="Custom");
dialog.enable({"hght": bCustom,"wdth":bCustom});
var nH = 0, nW = 0;

if(bCustom)
{
nH = (rslts["hght"] * m_bLastMult )/mult;
nW = (rslts["wdth"] * m_bLastMult)/mult;
}
else
{
var nLen = sizeList.length;
for(var i=0;i<nLen;i++)
{
if(sizeList[i].name == sel)
{
nH = sizeList[i].h/mult;
nW = sizeList[i].w/mult;
break;
}
}
}

this.wdthSheet = nW*mult;
this.hghtSheet = nH*mult;
var nSep = (rslts["Sepr"] * m_bLastMult )/mult;
var nTMarg = (rslts["TMrg"] * m_bLastMult )/mult;
var nBMarg = (rslts["BMrg"] * m_bLastMult )/mult;
var nRMarg = (rslts["RMrg"] * m_bLastMult )/mult;
var nLMarg = (rslts["LMrg"] * m_bLastMult )/mult;
this.sepDim = nSep*mult;
this.mrgTop = mult*nTMarg;
this.mrgBottom = mult*nBMarg;
this.mrgLeft = mult*nLMarg;
this.mrgRight = mult*nRMarg;

// Calculate the tile dims
var path = new Array();
var nRows = (this.GetListSel(rslts["Rows"],path))?path.reverse():"";
path = new Array();
var nCols = (this.GetListSel(rslts["Cols"],path))?path.reverse():"";
this.nRows = Math.floor(nRows);
this.nCols = Math.floor(nCols);
this.hghtTile = (this.hghtSheet - this.mrgTop - this.mrgBottom + this.sepDim)/nRows - this.sepDim;
this.wdthTile = (this.hghtTile * this.wdthPage)/this.hghtPage;
var tstDim = this.mrgLeft + this.mrgRight + nCols*this.wdthTile + (nCols-1)*this.sepDim;
if(tstDim > this.wdthSheet)
{// Reverse calc
this.wdthTile = (this.wdthSheet - this.mrgLeft - this.mrgRight + this.sepDim)/nCols - this.sepDim;
this.hghtTile = (this.wdthTile * this.hghtPage)/this.wdthPage;
}
// Adjust margins to center
tstDim = this.mrgLeft + this.mrgRight + nCols*this.wdthTile + (nCols-1)*this.sepDim;
var diff = this.wdthSheet - tstDim;
this.mrgLeft += diff/2;
tstDim = this.mrgTop + this.mrgBottom + nRows*this.hghtTile + (nRows-1)*this.sepDim;
diff = this.hghtSheet - tstDim;
this.mrgTop += diff/2;
var nPW = this.wdthPage/mult;
var nPH = this.hghtPage/mult;

var strIpt = "Source Page: Width = " + nPW + strUnits + "\n Height = " + nPH + strUnits;
dialog.load({"Inpt":strIpt,"hght":nH, "wdth":nW, "Sepr":nSep,"TMrg":nTMarg,"BMrg":nBMarg,"RMrg":nRMarg,"LMrg":nLMarg});
m_bLastMult = mult;
},
description:
{
name: "Tile PDF",
elements:
[
{
type: "view",
elements:
[
{
height: 51,
item_id: "Inpt",
multiline: "true",
name: "Static Text 1",
type: "static_text",
width: 332,
},
{
align_children: "align_top",
char_height: 8,
char_width: 8,
item_id: "cls1",
name: "Output Sheet Size",
type: "cluster",
elements:
[
{
char_height: 10,
height: 103,
type: "view",
elements:
[
{
alignment: "align_left",
height: 23,
item_id: "psiz",
type: "popup",
width: 53,
},
{
align_children: "align_row",
alignment: "align_left",
char_height: 8,
char_width: 8,
height: 27,
type: "view",
width: 148,
elements:
[
{
height: 23,
item_id: "sta1",
name: "Height",
type: "static_text",
},
{
alignment: "align_left",
char_width: 8,
height: 23,
item_id: "hght",
type: "edit_text",
variable_Name: "strShtHeight",
width: 88,
},
]
},
{
align_children: "align_row",
alignment: "align_left",
char_width: 8,
type: "view",
elements:
[
{
item_id: "sta1",
name: "Width:",
type: "static_text",
},
{
alignment: "align_left",
char_width: 8,
height: 23,
item_id: "wdth",
type: "edit_text",
variable_Name: "strShtWdth",
width: 88,
},
]
},
]
},
{
item_id: "cls1",
name: "Units",
type: "cluster",
elements:
[
{
group_id: "GRP1",
item_id: "Rad1",
name: "points",
next_tab: "Rad2",
type: "radio",
variable_Name: "strUnits",
},
{
group_id: "GRP1",
item_id: "Rad2",
name: "inches",
next_tab: "Rad3",
type: "radio",
},
{
group_id: "GRP1",
item_id: "Rad3",
name: "milimeters",
type: "radio",
},
]
},
]
},
{
align_children: "align_top",
char_height: 10,
type: "view",
elements:
[
{
char_height: 8,
char_width: 8,
item_id: "cls4",
name: "Layout",
type: "cluster",
elements:
[
{
align_children: "align_row",
alignment: "align_row",
type: "view",
elements:
[
{
alignment: "align_right",
char_width: 6,
item_id: "sta1",
name: "Rows",
type: "static_text",
},
{
char_width: 2,
item_id: "Rows",
name: "strRows",
type: "popup",
},
]
},
{
align_children: "align_row",
alignment: "align_top",
type: "view",
elements:
[
{
alignment: "align_right",
char_width: 6,
item_id: "sta2",
name: "Columns",
type: "static_text",
},
{
char_width: 2,
item_id: "Cols",
name: "strCols",
type: "popup",
},
]
},
{
align_children: "align_row",
alignment: "align_top",
type: "view",
elements:
[
{
alignment: "align_right",
char_width: 6,
item_id: "sta2",
name: "Separation",
type: "static_text",
},
{
char_width: 6,
item_id: "Sepr",
type: "edit_text",
variable_Name: "strSep",
},
]
},
]
},
{
char_height: 4,
char_width: 4,
item_id: "gap1",
type: "gap",
},
{
char_height: 8,
char_width: 8,
height: 174,
type: "view",
width: 121,
elements:
[
{
char_height: 4,
char_width: 4,
height: 125,
item_id: "img1",
type: "image",
width: 100,
},
{
item_id: "Rfsh",
name: "Refresh",
type: "button",
},
]
},
]
},
{
align_children: "align_center",
alignment: "align_left",
item_id: "cls3",
name: "Margins",
type: "cluster",
elements:
[
{
align_children: "align_row",
alignment: "align_center",
type: "view",
elements:
[
{
alignment: "align_right",
char_width: 3,
item_id: "sta2",
name: "Top",
type: "static_text",
},
{
char_width: 8,
item_id: "TMrg",
type: "edit_text",
variable_Name: "strTopMarg",
},
]
},
{
align_children: "align_row",
char_width: 8,
type: "view",
elements:
[
{
align_children: "align_row",
alignment: "align_top",
type: "view",
elements:
[
{
alignment: "align_right",
char_width: 3,
item_id: "sta2",
name: "Left",
type: "static_text",
},
{
char_width: 8,
item_id: "LMrg",
type: "edit_text",
variable_Name: "strLeftMarg",
},
]
},
{
align_children: "align_row",
alignment: "align_top",
type: "view",
elements:
[
{
alignment: "align_right",
char_width: 7,
item_id: "sta2",
name: "Right",
type: "static_text",
},
{
char_width: 8,
item_id: "RMrg",
type: "edit_text",
variable_Name: "strRightMarg",
},
]
},
]
},
{
align_children: "align_row",
alignment: "align_center",
type: "view",
elements:
[
{
alignment: "align_right",
char_width: 3,
item_id: "sta2",
name: "Bottom",
type: "static_text",
},
{
char_width: 8,
item_id: "BMrg",
type: "edit_text",
variable_Name: "strBotMarg",
},
]
},
]
},
{
align_children: "align_fill",
type: "ok_cancel",
},
]
},
]
}
};

// Example Code
TileDlg.strpsiz = ["Letter"];
TileDlg.strShtHeight = "";
TileDlg.strShtWdth = "";
TileDlg.strUnits = "Rad1";
TileDlg.strRows = ["1"];
TileDlg.strCols = ["1"];
TileDlg.strSep = "18";
TileDlg.strTopMarg = "36";
TileDlg.strLeftMarg = "36";
TileDlg.strRightMarg = "36";
TileDlg.strBotMarg = "36";
if("ok" == TileDlg.DoDialog())
{

    console.println("psiz:" + TileDlg.strpsiz);
    console.println("hght:" + TileDlg.strShtHeight);
    console.println("wdth:" + TileDlg.strShtWdth);
    console.println("GRP1:" + TileDlg.strUnits);
    console.println("Rows:" + TileDlg.strRows);
    console.println("Cols:" + TileDlg.strCols);
    console.println("Sepr:" + TileDlg.strSep);
    console.println("TMrg:" + TileDlg.strTopMarg);
    console.println("LMrg:" + TileDlg.strLeftMarg);
    console.println("RMrg:" + TileDlg.strRightMarg);
    console.println("BMrg:" + TileDlg.strBotMarg);
}