Copy link to clipboard
Copied
Good afternoon.
I am currently working ona project to create a dynamic stamp, that would allow the user to fill our a dialog form to fill the stamp, but will also allow users to 'restamp' by saving the entered information as variables, and repopulating the stamp witht he previous information if it isn't user overwitten. This essentially allows one to 'update' the stamp when actually deleting and refilling with stored/entered info. The issue I have is that the dialog box won't even show up when the stamp is placed, and I can't fill the information. For reference I tried to follow the code for creating multi-line dialog boxes using: https://community.adobe.com/t5/acrobat-sdk-discussions/create-a-multi-line-dialog-box-in-a-dynamic-s... .
CODE:
Copy link to clipboard
Copied
After corrected a misnamed text field the dialog box began showing, however the code was still wrong and would only fill the text fields with "BLANK" and would not eb overwritten. Changes were made, as on the commit function portion of teh code I used dialogstore() and used the variable names, but item_id shoudl have been used. After making this change, It began to work.
After alteration the effect was that the stamp when placed would create a dialog where a user can input necessary information and then enter to populate a stamp with the necessary info, if the user woudllike to update teh stamp, one can delete and just enter the fields that want to be changed and enter to 'update' the stamp. The onnly functionality I could not create was having the code give a BLANK display when the stamp is placed for the first time - instead the stamp displays what the previous stamp information was, even in other documents - im guessing because the variables are saved in the stamps files, not the document the stamp is applied, but if anyone knows please let me know why - My next steps would be to add a conditional statement where if the user inputs a " " (a space) then it resets to BLANK or something along that line.
And special thanks to TRY67 for the help !
Here is the most major code changed for reference:
the CODE's entirety:
if (event.source!=null && event.source.forReal && event.source.stampName == "#5VGSDi-y5TU9st_HVS7nkC") {
var StampDialog = {
result: "cancel",
DoDialog: function() {
return app.execDialog(this);
},
// Define the fields to be filled
PDTitle: "Defined",
WATitle: "Defined",
TDTitle: "Defined",
SystemTitle: "Defined",
DirTitle: "Defined",
SECTitle: "Defined",
TTitle: "Defined",
RTitle: "Defined",
CountyTitle: "Defined",
DateTitle: "Defined",
DBTitle: "Defined",
SNTitle: "Defined",
STTitle: "Defined",
DNTitle: "Defined",
initialize: function(dialog) {
var dlgInit = {
PDTitle: this.PDTitle,
WATitle: this.WATitle,
TDTitle: this.TDTitle,
SystemTitle: this.SystemTitle,
DirTitle: this.DirTitle,
SECTitle: this.SECTitle,
TTitle: this.TTitle,
RTitle: this.RTitle,
CountyTitle: this.CountyTitle,
DateTitle: this.DateTitle,
DBTitle: this.DBTitle,
SNTitle: this.SNTitle,
STTitle: this.STTitle,
DNTitle: this.DNTitle,
};
dialog.load(dlgInit);
},
// Commit the dialog results to the script variables
commit: function(dialog) {
var oRslt = dialog.store();
this.PDTitle = oRslt.PDTe || this.PDTitle;
this.WATitle = oRslt.WATe || this.WATitle;
this.TDTitle = oRslt.TDTe || this.TDTitle;
this.SystemTitle = oRslt.Syse || this.SystemTitle;
this.DirTitle = oRslt.Dire || this.DirTitle;
this.SECTitle = oRslt.SECe || this.SECTitle;
this.TTitle = oRslt.TTie || this.TTitle;
this.RTitle = oRslt.RTie || this.RTitle;
this.CountyTitle = oRslt.CTie || this.CountyTitle;
this.DateTitle = oRslt.DTie || this.DateTitle;
this.DBTitle = oRslt.DBTe || this.DBTitle;
this.SNTitle = oRslt.SNTe || this.SNTitle;
this.STTitle = oRslt.STTe || this.STTitle;
this.DNTitle = oRslt.DNTe || this.DNTitle;
},
// Description of the dialog layout
description: {
name: "Stamp Information Dialog",
elements: [{
type: "view",
elements: [{
type: "static_text",
item_id: "PDTs",
name: "Project Description:", // The text that appears on the label.
}, {
type: "edit_text", // A text input field where the user can enter data.
item_id: "PDTe", // An identifier for the text input field.
char_width: 20, // The width of the text input field in characters.
}, {
type: "static_text",
item_id: "WATs",
name: "Work Authorization:",
}, {
type: "edit_text",
item_id: "WATe",
char_width: 20,
}, {
type: "static_text",
item_id: "TDTs",
name: "Tax District:",
}, {
type: "edit_text",
item_id: "TDTe",
char_width: 20,
}, {
type: "static_text",
item_id: "Syss",
name: "System:",
}, {
type: "edit_text",
item_id: "Syse",
char_width: 20,
}, {
type: "static_text",
item_id: "Dirs",
name: "__ SEC. xx -T. xxx R. xx",
}, {
type: "edit_text",
item_id: "Dire",
char_width: 20,
}, {
type: "static_text",
item_id: "SECs",
name: "xx SEC. __ -T. xxx R. xx",
}, {
type: "edit_text",
item_id: "SECe",
char_width: 20,
}, {
type: "static_text",
item_id: "TTis",
name: "xx SEC. xx -T. ___ R. xx",
}, {
type: "edit_text",
item_id: "TTie",
char_width: 20,
}, {
type: "static_text",
item_id: "RTis",
name: "xx SEC. xx -T. xxx R. __",
}, {
type: "edit_text",
item_id: "RTie",
char_width: 20,
}, {
type: "static_text",
item_id: "CTis",
name: "County:",
}, {
type: "edit_text",
item_id: "CTie",
char_width: 20,
}, {
type: "static_text",
item_id: "DTis",
name: "Date:",
}, {
type: "edit_text",
item_id: "DTie",
char_width: 20,
}, {
type: "static_text",
item_id: "DBTs",
name: "Drawn By:",
}, {
type: "edit_text",
item_id: "DBTe",
char_width: 20,
}, {
type: "static_text",
item_id: "SNTs",
name: "Sheet No. (current):",
}, {
type: "edit_text",
item_id: "SNTe",
char_width: 20,
}, {
type: "static_text",
item_id: "STTs",
name: "Sheet Total No.:",
}, {
type: "edit_text",
item_id: "STTe",
char_width: 20,
}, {
type: "static_text",
item_id: "DNTs",
name: "Drawing No.:",
}, {
type: "edit_text",
item_id: "DNTe",
char_width: 20,
}, {
type: "ok_cancel", // The OK and Cancel buttons.
}]
}]
}
};
// Initialize fields with previous values or "BLANK"
StampDialog.PDTitle = this.getField("PDTitle").value ;
StampDialog.WATitle = this.getField("WATitle").value ;
StampDialog.TDTitle = this.getField("TDTitle").value ;
StampDialog.SystemTitle = this.getField("SystemTitle").value ;
StampDialog.DirTitle = this.getField("DirTitle").value ;
StampDialog.SECTitle = this.getField("SECTitle").value ;
StampDialog.TTitle = this.getField("TTitle").value ;
StampDialog.RTitle = this.getField("RTitle").value ;
StampDialog.CountyTitle = this.getField("CountyTitle").value ;
StampDialog.DateTitle = this.getField("DateTitle").value ;
StampDialog.DBTitle = this.getField("DBTitle").value ;
StampDialog.SNTitle = this.getField("SNTitle").value ;
StampDialog.STTitle = this.getField("STTitle").value ;
StampDialog.DNTitle = this.getField("DNTitle").value ;
// Show the dialog and process user input
if ("ok" == StampDialog.DoDialog()) {
this.getField("PDTitle").value = StampDialog.PDTitle;
this.getField("WATitle").value = StampDialog.WATitle;
this.getField("TDTitle").value = StampDialog.TDTitle;
this.getField("SystemTitle").value = StampDialog.SystemTitle;
this.getField("DirTitle").value = StampDialog.DirTitle;
this.getField("SECTitle").value = StampDialog.SECTitle;
this.getField("TTitle").value = StampDialog.TTitle;
this.getField("RTitle").value = StampDialog.RTitle;
this.getField("CountyTitle").value = StampDialog.CountyTitle;
this.getField("DateTitle").value = StampDialog.DateTitle;
this.getField("DBTitle").value = StampDialog.DBTitle;
this.getField("SNTitle").value = StampDialog.SNTitle;
this.getField("STTitle").value = StampDialog.STTitle;
this.getField("DNTitle").value = StampDialog.DNTitle;
}
}
Copy link to clipboard
Copied
[Merged with other post]
Copy link to clipboard
Copied
- Where did you place the code (under which event)?
- Are there error messages in the JS Console after you apply the stamp?
- Did you make sure the stampName value is correct for your stamp? If so, how?
Copy link to clipboard
Copied
- The code is under the custom calculation script if the text field "Script Title", which the last of 14 texts fields.
- I did not get any error messages, instead the stamp just placed but with no dialog, and no values entered into the text fields, not even BLANK which is the (supposed) default value
- The stamp name value I found by opening the dynamic file of the category the stamp is in and viewing the page templates using the organize pages tool.
let me know if I answered any of the questions incorrectly, I am still learning Acrobat.
Copy link to clipboard
Copied
Okay after correcting the text fields I was able to get eh dialog box to open, however I have a problem as now the BLANK designation is overriding the user input.
Copy link to clipboard
Copied
The ids of the elements in the dialog must be exactly four characters long for it to work correctly.
And I don't know what is the variable_Name property you defined for them. There's no such property in the documentation of this method. Use only item_id and apply the values to the variables in the commit function.
Copy link to clipboard
Copied
After corrected a misnamed text field the dialog box began showing, however the code was still wrong and would only fill the text fields with "BLANK" and would not eb overwritten. Changes were made, as on the commit function portion of teh code I used dialogstore() and used the variable names, but item_id shoudl have been used. After making this change, It began to work.
After alteration the effect was that the stamp when placed would create a dialog where a user can input necessary information and then enter to populate a stamp with the necessary info, if the user woudllike to update teh stamp, one can delete and just enter the fields that want to be changed and enter to 'update' the stamp. The onnly functionality I could not create was having the code give a BLANK display when the stamp is placed for the first time - instead the stamp displays what the previous stamp information was, even in other documents - im guessing because the variables are saved in the stamps files, not the document the stamp is applied, but if anyone knows please let me know why - My next steps would be to add a conditional statement where if the user inputs a " " (a space) then it resets to BLANK or something along that line.
And special thanks to TRY67 for the help !
Here is the most major code changed for reference:
the CODE's entirety:
if (event.source!=null && event.source.forReal && event.source.stampName == "#5VGSDi-y5TU9st_HVS7nkC") {
var StampDialog = {
result: "cancel",
DoDialog: function() {
return app.execDialog(this);
},
// Define the fields to be filled
PDTitle: "Defined",
WATitle: "Defined",
TDTitle: "Defined",
SystemTitle: "Defined",
DirTitle: "Defined",
SECTitle: "Defined",
TTitle: "Defined",
RTitle: "Defined",
CountyTitle: "Defined",
DateTitle: "Defined",
DBTitle: "Defined",
SNTitle: "Defined",
STTitle: "Defined",
DNTitle: "Defined",
initialize: function(dialog) {
var dlgInit = {
PDTitle: this.PDTitle,
WATitle: this.WATitle,
TDTitle: this.TDTitle,
SystemTitle: this.SystemTitle,
DirTitle: this.DirTitle,
SECTitle: this.SECTitle,
TTitle: this.TTitle,
RTitle: this.RTitle,
CountyTitle: this.CountyTitle,
DateTitle: this.DateTitle,
DBTitle: this.DBTitle,
SNTitle: this.SNTitle,
STTitle: this.STTitle,
DNTitle: this.DNTitle,
};
dialog.load(dlgInit);
},
// Commit the dialog results to the script variables
commit: function(dialog) {
var oRslt = dialog.store();
this.PDTitle = oRslt.PDTe || this.PDTitle;
this.WATitle = oRslt.WATe || this.WATitle;
this.TDTitle = oRslt.TDTe || this.TDTitle;
this.SystemTitle = oRslt.Syse || this.SystemTitle;
this.DirTitle = oRslt.Dire || this.DirTitle;
this.SECTitle = oRslt.SECe || this.SECTitle;
this.TTitle = oRslt.TTie || this.TTitle;
this.RTitle = oRslt.RTie || this.RTitle;
this.CountyTitle = oRslt.CTie || this.CountyTitle;
this.DateTitle = oRslt.DTie || this.DateTitle;
this.DBTitle = oRslt.DBTe || this.DBTitle;
this.SNTitle = oRslt.SNTe || this.SNTitle;
this.STTitle = oRslt.STTe || this.STTitle;
this.DNTitle = oRslt.DNTe || this.DNTitle;
},
// Description of the dialog layout
description: {
name: "Stamp Information Dialog",
elements: [{
type: "view",
elements: [{
type: "static_text",
item_id: "PDTs",
name: "Project Description:", // The text that appears on the label.
}, {
type: "edit_text", // A text input field where the user can enter data.
item_id: "PDTe", // An identifier for the text input field.
char_width: 20, // The width of the text input field in characters.
}, {
type: "static_text",
item_id: "WATs",
name: "Work Authorization:",
}, {
type: "edit_text",
item_id: "WATe",
char_width: 20,
}, {
type: "static_text",
item_id: "TDTs",
name: "Tax District:",
}, {
type: "edit_text",
item_id: "TDTe",
char_width: 20,
}, {
type: "static_text",
item_id: "Syss",
name: "System:",
}, {
type: "edit_text",
item_id: "Syse",
char_width: 20,
}, {
type: "static_text",
item_id: "Dirs",
name: "__ SEC. xx -T. xxx R. xx",
}, {
type: "edit_text",
item_id: "Dire",
char_width: 20,
}, {
type: "static_text",
item_id: "SECs",
name: "xx SEC. __ -T. xxx R. xx",
}, {
type: "edit_text",
item_id: "SECe",
char_width: 20,
}, {
type: "static_text",
item_id: "TTis",
name: "xx SEC. xx -T. ___ R. xx",
}, {
type: "edit_text",
item_id: "TTie",
char_width: 20,
}, {
type: "static_text",
item_id: "RTis",
name: "xx SEC. xx -T. xxx R. __",
}, {
type: "edit_text",
item_id: "RTie",
char_width: 20,
}, {
type: "static_text",
item_id: "CTis",
name: "County:",
}, {
type: "edit_text",
item_id: "CTie",
char_width: 20,
}, {
type: "static_text",
item_id: "DTis",
name: "Date:",
}, {
type: "edit_text",
item_id: "DTie",
char_width: 20,
}, {
type: "static_text",
item_id: "DBTs",
name: "Drawn By:",
}, {
type: "edit_text",
item_id: "DBTe",
char_width: 20,
}, {
type: "static_text",
item_id: "SNTs",
name: "Sheet No. (current):",
}, {
type: "edit_text",
item_id: "SNTe",
char_width: 20,
}, {
type: "static_text",
item_id: "STTs",
name: "Sheet Total No.:",
}, {
type: "edit_text",
item_id: "STTe",
char_width: 20,
}, {
type: "static_text",
item_id: "DNTs",
name: "Drawing No.:",
}, {
type: "edit_text",
item_id: "DNTe",
char_width: 20,
}, {
type: "ok_cancel", // The OK and Cancel buttons.
}]
}]
}
};
// Initialize fields with previous values or "BLANK"
StampDialog.PDTitle = this.getField("PDTitle").value ;
StampDialog.WATitle = this.getField("WATitle").value ;
StampDialog.TDTitle = this.getField("TDTitle").value ;
StampDialog.SystemTitle = this.getField("SystemTitle").value ;
StampDialog.DirTitle = this.getField("DirTitle").value ;
StampDialog.SECTitle = this.getField("SECTitle").value ;
StampDialog.TTitle = this.getField("TTitle").value ;
StampDialog.RTitle = this.getField("RTitle").value ;
StampDialog.CountyTitle = this.getField("CountyTitle").value ;
StampDialog.DateTitle = this.getField("DateTitle").value ;
StampDialog.DBTitle = this.getField("DBTitle").value ;
StampDialog.SNTitle = this.getField("SNTitle").value ;
StampDialog.STTitle = this.getField("STTitle").value ;
StampDialog.DNTitle = this.getField("DNTitle").value ;
// Show the dialog and process user input
if ("ok" == StampDialog.DoDialog()) {
this.getField("PDTitle").value = StampDialog.PDTitle;
this.getField("WATitle").value = StampDialog.WATitle;
this.getField("TDTitle").value = StampDialog.TDTitle;
this.getField("SystemTitle").value = StampDialog.SystemTitle;
this.getField("DirTitle").value = StampDialog.DirTitle;
this.getField("SECTitle").value = StampDialog.SECTitle;
this.getField("TTitle").value = StampDialog.TTitle;
this.getField("RTitle").value = StampDialog.RTitle;
this.getField("CountyTitle").value = StampDialog.CountyTitle;
this.getField("DateTitle").value = StampDialog.DateTitle;
this.getField("DBTitle").value = StampDialog.DBTitle;
this.getField("SNTitle").value = StampDialog.SNTitle;
this.getField("STTitle").value = StampDialog.STTitle;
this.getField("DNTitle").value = StampDialog.DNTitle;
}
}
Copy link to clipboard
Copied
All field interaction using the document object this refers to the stamp file. If you want to interact with the document being stamp, that document object is event.source.source. It is possible to create an "editable" dynamic stamp where subsequent stampings prepopulate the dialog fields with the previously stamped values, delete the stamp, and apply a new one. There are two methods (that I know) of for this. One is to create form fields in the document being stamped in your script and store the values there. Another is to create a hidden annotation and store the values there. You don't need to populate "BLANK" the first time it is used. Simply populate with the value of your storage in the event.source.source document (which will be empty in the dialog before the stamp is applied the first time). You can also read the rect property of the previous stamp and apply it to the replacement stamp so that it lands in the exact location of the deleted stamp.
Copy link to clipboard
Copied
Interesting so would the second method mean storing the code in the stamp text field same as before but it runs at a document level meaning it uses the last known variable associated to that specific document being placed on, thus meaning there is no prior value and will auto-blank? Is therea difference between a hidden annotation and a text field? Also it was under my assumption that stamps become flattened after being placed so would form fields not dissapear once placed?
Thanks for the help.
Copy link to clipboard
Copied
The fields are flattened, but if you know the location of the stamp then you can calculate where they were in relation to it. Just remember that the size of the stamp might have been changed, so you will need to adjust not just their locations, but also their (relative) size to it. This is quite a complex scripting task.
Copy link to clipboard
Copied
So you could theoretically have some code that would run within a stamp that would save its location data when placed, save its inputs as document variables, and then also run code that allows the stamp to check if there is one on the doument placed (?) and delete the stamp and recreate it with text fields or just place it for the first time
Would the stamp need to be placed in the same location or would the text field locations be relative to the actual placement of the stamp (x+99) and (y+99) with x,y as stamp location?
Copy link to clipboard
Copied
No, it will have to be an external script. The scripts in the stamp itself run just before it is applied, so they can't know where it's being placed. Once placed, though, you can select it and then run another script on it and that script could use its current location and size to recreate it.
Copy link to clipboard
Copied
Ah, I see I'm constrained to just the stamp for this, but I'm happy with the result regardless, especially if I patch the variables into the document object. Would that process for the most part just be changing the 'this.' into 'event.source.source' ?
Copy link to clipboard
Copied
Here's a video of an editable dynamic stamp I made 8 years ago, using the form field method for storage. In this video the stamp doesn't land in the same location but I have since modified how we do these so they match the location of the original stamp after destroying it. No external script required.
Copy link to clipboard
Copied
It doesn't save the location data. The script gets the location by looping through the annotations in the document being stamped (event.source.source) and matching the AP of the stamp, then acquiring the rect properties (location on the page) of that annotation.
Copy link to clipboard
Copied
No. The code creates hidden text fields in the document being stamped, or a hidden annotation, and stores the data there. The difference is that the annotation method will work on documents that are encrypted and "prevent changes to the document", as long as it doesn't prevent "commenting", in which case you wouldn't be able to stamp it anyway. So the annotation storage method is more flexible.
Copy link to clipboard
Copied
I don't see the code anywhere in the file...
Copy link to clipboard
Copied
Copy link to clipboard
Copied
This code is slightly different from posted, only being that the variable names in the attached code are matching with the item_id values.
Copy link to clipboard
Copied
Check the JS Console (Ctrl+J) after applying the stamp.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Would this be because of mislabeled variables? - while creating the code I was a little confused sometiems when the line would refere to the variable or to the text field
Copy link to clipboard
Copied
> Would this be because of mislabeled variables?
No. The variable names don't have to match the field names, but the field name strings in the code do have to match those in the actual file.
Copy link to clipboard
Copied
Right. So there are errors in your code. The first one happens when you apply the code. You can solve it by changing the first line to:
if (event.source!=null && event.source.forReal && event.source.stampName == "#5VGSDi-y5TU9st_HVS7nkC") {
But this is not a major issue.
The second one is about an invalid field name in your code. Go to that line, and search for any misspellings. Even a single letter off (hint hint) could cause it to fail.
Copy link to clipboard
Copied
Thank you, I did not know that errors were viewed using that. So would that second issue be the only one or is it rather where teh JS script got 'stuck' and hence ran teh line 9 times before ending? In which case I would fix the line and then run, use JS Console and iterate that process?
Thank you
Find more inspiration, events, and resources on the new Adobe Community
Explore Now