VariableDataFormTemplate = app.trustedFunction(
function() {
app.beginPriv();
//-----------------------------------------------
var doc = this;
var templateFoterArr = getFieldByPattern ("TemplateFooter", doc);
for (var i = 0 ; i < templateFoterArr.length ; i++) {
t = templateFoterArr[i];
for (var n = 0 ; n < doc.numPages ; n++) {
addDataFields (t, n, doc)
};
var tv = t.value;
t.value = "";
t.value = tv;
var tPos = t.rect;
t.rect = [tPos[0],tPos[1]*2-tPos[3], tPos[2], tPos[1]];
};
//-----------------------------------------------
app.endPriv();
});
function addDataFields (t, nP, doc) {
var fName = t.name.replace("Template", "Data") + " " + nP;
doc.removeField(fName);
var f = doc.addField(fName, "text", nP, t.rect);
for ( var i in t ) {
try {
if ( typeof t[i] != "function" ) f[i] = t[i];
} catch(e) {};
};
var cScript = ['var tplValue = this.getField("'+t.name+'").value',
'var page = this.getField("'+fName+'").page+1',
'var pages = this.numPages',
'tplValue = tplValue.replace(/(<page>)/g, page)',
'tplValue = tplValue.replace(/(<pages>)/g, pages)',
'this.getField("'+fName+'").value = tplValue'].join('\n');
f.display = display.visible;
f.readonly = true;
f.setAction("Calculate", cScript);
};
function getFieldByPattern (pattern, doc) {
var tArr = [];
for (var i = 0 ; i < doc.numFields ; i++) {
var fn = doc.getNthFieldName(i) ;
if (fn.indexOf(pattern)>=0) {
tArr.push (doc.getField(fn))
};
};
return tArr;
};
app.addMenuItem({
cName: 'VariableDataFormTemplate',
cParent: 'Edit',
cExec: 'VariableDataFormTemplate()'
});