The following code is used in the custom calculation script of the txt1 text field in the InvoiceStamp1 pdf. The lines of problem code are maked with the comment "Problem code". If I ommit the problem code lines the stamp works properly. After reading ls_rbls comment and the reference doc they sent, I think my problem may be that I don't know how to (or if its possible to) use the .getPageNthWord() function inside of a stamp. I did a little bit of testing and I could get the getPageNthWord function to return words from the stamp pdf, but cannot get words from the page of the document the stamp is being applied to. Any insight and help is much appreciated.
// Start code
// Tested on Adobe DC Pro version 2020.013.20066
// when any stamp in the Stamp File is being placed on the document and when stamp has this name
if (event.source.forReal && (event.source.stampName == "#InvoiceStamp1"))
{
// trims beginning and end of string. Gets rid of leading and trailing; spaces, line feed, caridge returns, horizontal tabs.
function trim (str) {
return str.replace (/(^[\s\n\r\t\x0B]+)|([\s\n\r\t\x0B]+$)/g, '');
};
var JSADMDlg1 = {
result: "cancel",
DoDialog: function() {
return app.execDialog(this);
},
vendor: "vend",
invoice: "inv#",
invoicedatem: "idtm",
invoicedated: "idtd",
invoicedatey: "idty",
dateofrecordm: "dorm",
dateofrecordy: "dory",
invoicedescription: "txt5",
company: "txt6",
project: "txt7",
job: "txt8",
costcode: "txt9",
amount: "tzt1",
glcode: "tzt2",
duedatem: "ddtm",
duedated: "ddtd",
duedatey: "ddty",
// method that runs when the dialog box is created
initialize: function(dialog) {
var dlgInit = {
"vend": this.vendor,
"inv#": this.invoice,
"idtm": this.invoicedatem,
"idtd": this.invoicedated,
"idty": this.invoicedatey,
"dorm": this.dateofrecordm,
"dory": this.dateofrecordy,
"txt5": this.invoicedescription,
"txt6": this.company,
"txt7": this.project,
"txt8": this.job,
"txt9": this.costcode,
"tzt1": this.amount,
"tzt2": this.glcode,
"ddtm": this.duedatem,
"ddtd": this.duedated,
"ddty": this.duedatey,
};
dialog.load(dlgInit);
},
//validate dialog box. validation occurs after pressing the OK button
validate: function(dialog) {
var oVslt = dialog.store();
if (trim(oVslt["vend"]).length > 7) {
app.alert("Vendor Code\nMust be 7 or less characters long");
return false;
};
var tidtm = trim(oVslt["idtm"]);
var tidtd = trim(oVslt["idtd"]);
var tidty = trim(oVslt["idty"]);
if(tidtm != ""){
if (tidtm < 1 || tidtm > 13 || isNaN(tidtm)) {
app.alert("Invoice Date (Month)\nMust be a number between 1 and 12 or left blank");
return false;
};
};
if(tidtd != ""){
if (tidtd < 1 || tidtd > 31 || isNaN(tidtd)) {
app.alert("Invoice Date (Day)\nMust be a number between 1 and 31 or left blank");
return false;
};
};
if(tidty != ""){
if (tidty < 1 || tidty > 99 || isNaN(tidty)) {
app.alert("Invoice Date (Year)\nMust be a number between 1 and 99 or left blank");
return false;
};
};
if (tidtm.length == 1) {
tidtm = "0" + tidtm;
};
if (tidtd.length == 1) {
tidtd = "0" + tidtd;
};
if (tidty.length == 1) {
tidty = "0" + tidty;
};
if(tidtm != "" && tidtd != "" && tidty != ""){
if (util.scand("mm-dd-yy", tidtm + "-" + tidtd + "-" + tidty) == null) {
app.alert("Invoice Date\nThe enetered date is not a valid date.");
return false;
};
};
if (trim(oVslt["inv#"]).length > 8) {
app.alert("Invoice #\nMust be 8 or less characters long");
return false;
};
if(trim(oVslt["dorm"]) != ""){
if (trim(oVslt["dorm"]) < 1 || trim(oVslt["dorm"]) > 13 || isNaN(trim(oVslt["dorm"]))) {
app.alert("Date of Record (Month)\nMust be a number between 1 and 12 or left blank");
return false;
};
};
if(trim(oVslt["dory"]) != ""){
if (trim(oVslt["dory"]) < 0 || trim(oVslt["dory"]) > 99 || isNaN(trim(oVslt["dory"]))) {
app.alert("Date of Record (Year)\nMust be a number between 00 and 99 or left blank");
return false;
};
};
if(trim(oVslt["txt6"]) != ""){
if (trim(oVslt["txt6"]) < 1 || trim(oVslt["txt6"]) > 9999 || isNaN(trim(oVslt["txt6"]))) {
app.alert("Company #\nMust be a number between 1 and 9999 or left blank");
return false;
};
};
if(trim(oVslt["txt7"]) != ""){
if (trim(oVslt["txt7"]) < 1 || trim(oVslt["txt7"]) > 99999 || isNaN(trim(oVslt["txt7"]))) {
app.alert("Project #\nMust be a number between 1 and 99999 or left blank");
return false;
};
};
if (trim(oVslt["txt8"]).length > 5) {
app.alert("Job #\nMust be 5 or less characters long");
return false;
};
if(trim(oVslt["txt9"]) != ""){
if (trim(oVslt["txt9"]) < 1 || trim(oVslt["txt9"]) > 99999 || isNaN(trim(oVslt["txt9"]))) {
app.alert("Cost Code\nMust be a number between 1 and 99999 or left blank");
return false;
};
};
if (isNaN(trim(oVslt["tzt1"]))) {
app.alert("Total Amount\nMust be a number");
return false;
};
var tddtm = trim(oVslt["ddtm"]);
var tddtd = trim(oVslt["ddtd"]);
var tddty = trim(oVslt["ddty"]);
if(tddtm != ""){
if (tddtm < 1 || tddtm > 13 || isNaN(tddtm)) {
app.alert("Due Date (Month)\nMust be a number between 1 and 12 or left blank");
return false;
};
};
if(tddtd != ""){
if (tddtd < 1 || tddtd > 31 || isNaN(tddtd)) {
app.alert("Due Date (Day)\nMust be a number between 1 and 31 or left blank");
return false;
};
};
if(tddty != ""){
if (tddty < 1 || tddty > 99 || isNaN(tddty)) {
app.alert("Due Date (Year)\nMust be a number between 1 and 99 or left blank");
return false;
};
};
if (tddtm.length == 1) {
tddtm = "0" + tddtm;
};
if (tddtd.length == 1) {
tddtd = "0" + tddtd;
};
if (tddty.length == 1) {
tddty = "0" + tddty;
};
if(tddtm != "" && tddtd != "" && tddty != ""){
if(util.scand("mm-dd-yy", tddtm + "-" + tddtd + "-" + tddty) == null){
app.alert("Due Date\nThe enetered date is not a valid date.");
return false;
};
};
return true;
},
//method that is called when OK button is selected
commit: function(dialog) {
var oRslt = dialog.store();
this.vendor = trim(oRslt["vend"]).toUpperCase();
this.invoice = trim(oRslt["inv#"]).toUpperCase();
this.invoicedatem = trim(oRslt["idtm"]).toUpperCase();
this.invoicedated = trim(oRslt["idtd"]).toUpperCase();
this.invoicedatey = trim(oRslt["idty"]).toUpperCase();
this.dateofrecordm = trim(oRslt["dorm"]).toUpperCase();
this.dateofrecordy = trim(oRslt["dory"]).toUpperCase();
this.invoicedescription = trim(oRslt["txt5"]).toUpperCase();
this.company = trim(oRslt["txt6"]).toUpperCase();
this.project = trim(oRslt["txt7"]).toUpperCase();
this.job = trim(oRslt["txt8"]).toUpperCase();
this.costcode = trim(oRslt["txt9"]).toUpperCase();
this.amount = trim(oRslt["tzt1"]).toUpperCase();
this.glcode = trim(oRslt["tzt2"]).toUpperCase();
this.duedatem = trim(oRslt["ddtm"]).toUpperCase();
this.duedated = trim(oRslt["ddtd"]).toUpperCase();
this.duedatey = trim(oRslt["ddty"]).toUpperCase();
},
description: {
name: "JSADM Dialog",
elements: [
{
type: "view",
elements: [
{
type: "static_text",
item_id: "hed1",
name: "Press \"Tab\" or \"Shift + Tab\" to easily move between fields"
},
{
type: "view",
elements: [
{
type: "view",
align_children: "align_row",
elements: [
{
type: "static_text",
item_id: "sta1",
name: "Vendor Code",
char_width: 10,
},
{
type: "edit_text",
item_id: "vend",
variable_Name: "vendor",
char_width: 7,
}
]
},
{
type: "view",
align_children: "align_row",
elements: [
{
type: "static_text",
item_id: "sta2",
name: "Invoice #",
char_width: 10,
},
{
type: "edit_text",
item_id: "inv#",
variable_Name: "invoice",
char_width: 8,
}
]
},
{
type: "cluster",
align_children: "align_row",
elements: [
{
type: "static_text",
item_id: "sta3",
name: "Invoice Date",
char_width: 8,
},
{
type: "view",
align_children: "align_fill",
elements: [
{
type: "static_text",
item_id: "st3m",
name: "Month",
},
{
type: "edit_text",
item_id: "idtm",
variable_Name: "invoicedatem",
}
]
},
{
type: "view",
align_children: "align_fill",
elements: [
{
type: "static_text",
item_id: "st3d",
name: "Day",
},
{
type: "edit_text",
item_id: "idtd",
variable_Name: "invoicedated",
}
]
},
{
type: "view",
align_children: "align_fill",
elements: [
{
type: "static_text",
item_id: "st3y",
name: "Year",
},
{
type: "edit_text",
item_id: "idty",
variable_Name: "invoicedatey",
}
]
},
]
},
{
type: "cluster",
align_children: "align_row",
elements: [
{
type: "static_text",
item_id: "sta4",
name: "Date of Record",
char_width: 7,
},
{
type: "view",
align_children: "align_fill",
elements: [
{
type: "static_text",
item_id: "st4m",
name: "Month",
},
{
type: "edit_text",
item_id: "dorm",
variable_Name: "dateofrecordm",
}
]
},
{
type: "view",
align_children: "align_fill",
elements: [
{
type: "static_text",
item_id: "st4y",
name: "Year",
},
{
type: "edit_text",
item_id: "dory",
variable_Name: "dateofrecordy",
}
]
},
]
},
{
type: "view",
align_children: "align_row",
elements: [
{
type: "static_text",
item_id: "sta5",
name: "Description",
char_width: 10,
},
{
type: "edit_text",
item_id: "txt5",
variable_Name: "invoicedescription",
char_width: 10,
}
]
},
{
type: "view",
align_children: "align_row",
elements: [
{
type: "static_text",
item_id: "sta6",
name: "Company #",
char_width: 10,
},
{
type: "edit_text",
item_id: "txt6",
variable_Name: "company",
char_width: 4,
}
]
},
{
type: "cluster",
elements: [
{
type: "view",
align_children: "align_row",
elements: [
{
type: "static_text",
item_id: "sta7",
name: "Project #",
char_width: 8,
},
{
type: "edit_text",
item_id: "txt7",
variable_Name: "project",
char_width: 5,
}
]
},
{
type: "view",
align_children: "align_row",
elements: [
{
type: "static_text",
item_id: "sta8",
name: "Job #",
char_width: 8,
},
{
type: "edit_text",
item_id: "txt8",
variable_Name: "job",
char_width: 5,
}
]
},
{
type: "view",
align_children: "align_row",
elements: [
{
type: "static_text",
item_id: "sta9",
name: "Cost Code",
char_width: 8,
},
{
type: "edit_text",
item_id: "txt9",
variable_Name: "costcode",
char_width: 5,
}
]
}
]
},
{
type: "view",
align_children: "align_row",
elements: [
{
type: "static_text",
item_id: "st10",
name: "Total Amount",
char_width: 10,
},
{
type: "edit_text",
item_id: "tzt1",
variable_Name: "amount",
char_width: 12,
}
]
},
{
type: "view",
align_children: "align_row",
elements: [
{
type: "static_text",
item_id: "st11",
name: "GL Code",
char_width: 10,
},
{
type: "edit_text",
item_id: "tzt2",
variable_Name: "glcode",
char_width: 15,
}
]
},
{
type: "cluster",
align_children: "align_row",
elements: [
{
type: "static_text",
item_id: "st12",
name: "Due Date",
char_width: 8,
},
{
type: "view",
align_children: "align_fill",
elements: [
{
type: "static_text",
item_id: "s13m",
name: "Month",
},
{
type: "edit_text",
item_id: "ddtm",
variable_Name: "duedatem",
}
]
},
{
type: "view",
align_children: "align_fill",
elements: [
{
type: "static_text",
item_id: "s13d",
name: "Day",
},
{
type: "edit_text",
item_id: "ddtd",
variable_Name: "duedated",
}
]
},
{
type: "view",
align_children: "align_fill",
elements: [
{
type: "static_text",
item_id: "s13y",
name: "Year",
},
{
type: "edit_text",
item_id: "ddty",
variable_Name: "duedatey",
}
]
},
]
},
]
},
{
type: "ok_cancel",
alignment: "align_right",
},
]
}, ]
}
};
// set initial values for dialog text fields
var test1 = event.target.doc.getPageNthWord(0,0); //Problem code
// var test1 = this.getPageNthWord(0,0); //Problem code
JSADMDlg1.vendor = toString(test1); //Problem code
// JSADMDlg1.vendor = " ";
JSADMDlg1.invoice = " ";
JSADMDlg1.invoicedatem = " ";
JSADMDlg1.invoicedated = " ";
JSADMDlg1.invoicedatey = " ";
JSADMDlg1.dateofrecordm = " ";
JSADMDlg1.dateofrecordy = " ";
JSADMDlg1.invoicedescription = " ";
JSADMDlg1.company = " ";
JSADMDlg1.project = " ";
JSADMDlg1.job = " ";
JSADMDlg1.costcode = " ";
JSADMDlg1.amount = " ";
JSADMDlg1.glcode = " ";
JSADMDlg1.duedatem = " ";
JSADMDlg1.duedated = " ";
JSADMDlg1.duedatey = " ";
//set the stamp text field to equal the entered dialog text fields
if ("ok" == JSADMDlg1.DoDialog()) {
this.getField("txt1").value = JSADMDlg1.vendor;
this.getField("txt2").value = JSADMDlg1.invoice;
if (JSADMDlg1.invoice.length < 11) {
this.getField("txt2").textSize = 11;
} else {
this.getField("txt2").textSize = 0;
};
if (JSADMDlg1.invoicedatem == "" && JSADMDlg1.invoicedated == "" && JSADMDlg1.invoicedatey == "") {
this.getField("txt3").value = "";
} else if (JSADMDlg1.invoicedatem == "" || JSADMDlg1.invoicedated == "" || JSADMDlg1.invoicedatey == ""){
this.getField("txt3").value = JSADMDlg1.invoicedatem + "/" + JSADMDlg1.invoicedated + "/" + JSADMDlg1.invoicedatey;
} else {
var tempidt = JSADMDlg1.invoicedatem + "-" + JSADMDlg1.invoicedated + "-" + JSADMDlg1.invoicedatey;
var tempidt1 = util.scand("mm-dd-yy", tempidt);
this.getField("txt3").value = util.printd("mm/dd/yy", tempidt1);
};
if (JSADMDlg1.dateofrecordm == "" && JSADMDlg1.dateofrecordy == "") {
this.getField("txt4").value = "";
} else if (JSADMDlg1.dateofrecordm == "" || JSADMDlg1.dateofrecordy == ""){
this.getField("txt4").value = JSADMDlg1.dateofrecordm + "/" + JSADMDlg1.dateofrecordy;
} else {
var tempdrt = JSADMDlg1.dateofrecordm + "-" + JSADMDlg1.dateofrecordy;
var tempdrt1 = util.scand("mm-yy", tempdrt);
this.getField("txt4").value = util.printd("mm/yy", tempdrt1);
};
this.getField("txt5").value = JSADMDlg1.invoicedescription;
if (JSADMDlg1.invoicedescription.length < 11) {
this.getField("txt5").textSize = 11;
} else {
this.getField("txt5").textSize = 0;
};
this.getField("txt6").value = JSADMDlg1.company;
this.getField("txt7").value = JSADMDlg1.project;
this.getField("txt8").value = JSADMDlg1.job;
this.getField("txt9").value = JSADMDlg1.costcode;
//format amount dialog entry to round to two decial places, contain thousands commas, and have a $ symbol in front, have negative values be containted in parenthesis
if (JSADMDlg1.amount != "") {
var absamount = Math.abs(JSADMDlg1.amount);
if (JSADMDlg1.amount < 0) {
this.getField("tzt1").value = "$(" + util.printf("%,0.2f", absamount) + ")";
} else {
this.getField("tzt1").value = util.printf("$%,0.2f", JSADMDlg1.amount);
};
if (this.getField("tzt1").value.length < 13) {
this.getField("tzt1").textSize = 11;
} else {
this.getField("tzt1").textSize = 0;
};
} else {
this.getField("tzt1").value = JSADMDlg1.amount;
};
this.getField("tzt2").value = JSADMDlg1.glcode;
if (JSADMDlg1.glcode.length < 11) {
this.getField("tzt2").textSize = 11;
} else {
this.getField("tzt2").textSize = 0;
};
if (JSADMDlg1.duedatem == "" && JSADMDlg1.duedated == "" && JSADMDlg1.duedatey == "") {
this.getField("tzt3").value = "";
} else if (JSADMDlg1.duedatem == "" || JSADMDlg1.duedated == "" || JSADMDlg1.duedatey == ""){
this.getField("tzt3").value = JSADMDlg1.duedatem + "/" + JSADMDlg1.duedated + "/" + JSADMDlg1.duedatey;
} else {
var tempddt = JSADMDlg1.duedatem + "-" + JSADMDlg1.duedated + "-" + JSADMDlg1.duedatey;
var tempddt1 = util.scand("mm-dd-yy", tempddt);
this.getField("tzt3").value = util.printd("mm/dd/yy", tempddt1);
};
}
}
// End code