Skip to main content
Participant
June 3, 2024
Question

Dynamic Stamp with dropdown

  • June 3, 2024
  • 4 replies
  • 1142 views

Hi mates

I am searching for a simple javascript, which is asks for user input when adding a new stamp. the userinput should be a dropdown field with 5 selectable values.

 

somebody already did this?
thx

This topic has been closed for replies.

4 replies

bebarth
Community Expert
Community Expert
June 4, 2024

Hi,
Here is an example for a stamp with a dropdown and  a quick script:

var theItems=["item #1","item #2","item #3","item #4","item #5"];
var theField="- Select an Item -";
var theList="var theList \= \{\""+theField+"\": "+(theItems.length+1)+",";
for (var i=0; i<theItems.length; i++) {
	var itemName=theItems[i];
	theList+="\""+itemName+"\": "+(-1*(i+1)).toString()+",";
}
var theList=theList.substring(0,theList.length-1);
theList+="\}";
eval(theList);
var dialogBox={
	initialize: function(dialogBox) {
		this.loadDefaults(dialogBox);
	},
	loadDefaults: function(dialogBox) {
		dialogBox.load({
			LCha: theList,
		})
	},
	validate: function(dialogBox) {
		var oRslt=dialogBox.store();
		var elements=dialogBox.store()["LCha"];
		var testOK=true;
		for (var i in elements) {
			if (elements[i]>0) {
				listValue=theList[i];
				listName=i;
			}
		}
		if (listValue>0) var testOK=false;
		if (!testOK) app.alert("Please select an item",3);
		return testOK;
	},
	description: {
		name: "Stamp with Dropdown",
		elements: [
			{
				type: "view",
				elements: [
					{
						type: "view",
						alignment: "align_fill",
						elements: [
							{
								type: "static_text",
								name: "Items",
								font: "dialog",
								bold: true,
							},
							{
								type: "popup",
								item_id: "LCha",
								width: 150,
								alignment: "align_fill",
							},
						]
					},
					{
						type: "gap",
						height: 5
					},
					{
						type: "ok_cancel",
					},
				]
			},
		]
	}
};
if (event.source.forReal && event.source.stampName=="#bebarth") {
	if("ok"==app.execDialog(dialogBox)){
		event.value=listName;
	}
}

@+

Participant
June 4, 2024

you are the hero of the week!!! thank you!!!

Thom Parker
Community Expert
Community Expert
June 3, 2024

I have created many dynamic stamps that use dropdowns as input. However, it is not simple. You need to use a custom dialog.  Read these articles.

https://acrobatusers.com/tutorials/dynamic_stamp_secrets/

https://www.pdfscripting.com/public/ACRODIALOGS-OVERVIEW.cfm

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
try67
Community Expert
Community Expert
June 3, 2024

Adding a drop-down to the stamp itself is not necessary, since the user can't interact with it anyway. Add a simple text field, but use a drop-down element in the dialog that is used to prompt the user to enter their input when the stamp is applied. Then copy their input into the various fields in the stamp.

PDF Automation Station
Community Expert
Community Expert
June 3, 2024

Look up popup under property type of the execDialog app method in the Acrobat JavaScript reference guide.