Create dynamic stamp with prefix and counter

This Forum is for the use of End Users requiring help and assistance for Tracker Software's PDF-Tools.

Moderators: PDF-XChange Support, Daniel - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Vasyl - PDF-XChange, Stefan - PDF-XChange

bmt84
User
Posts: 6
Joined: Wed Jul 25, 2018 10:28 am

Create dynamic stamp with prefix and counter

Post by bmt84 »

Hi All,

After extensive search on Internet I hope you guys can help me.
I'd like to have a dynamic stamp with prefix + counter. Every first time I add the stamp there should be a text field I can put a prefix and an starting number. After thatm every new stamp I place should have a higher number.

Is this possible?

I already tried this by making a new stamp and added a text macro and a counter macro

Code: Select all

// Extension for TT and T
function expandTT(format, date) {
	TT = "$1" + util.printd("tt", date).toUpperCase().split('').map(char => '\\' + char).join('');
	T = "$1" + util.printd("t", date).toUpperCase().split('').map(char => '\\' + char).join('');

	format = format.replaceAll(/(^|[^\\])TT/g, TT);
	format = format.replaceAll(/(^|[^\\])T/g, T);
	return format;
}

var dlg =
{
	result: "cancel",
	DoDialog: function () { return app.execDialog(this); },
	// Generated Variables
	aStrVariables: ["", ],


	initialize: function (dialog) {
		var dlgInit = {
			"#ICFvW7rYU56MUEPWZ0ryi0#iaText": this.aStrVariables[0],
		};
		dialog.load(dlgInit);
	},

	commit: function (dialog) {
		var oRslt = dialog.store();
		this.aStrVariables[0] = oRslt["#ICFvW7rYU56MUEPWZ0ryi0#iaText"];
	},

	"#ICFvW7rYU56MUEPWZ0ryi0#iaText": function (dialog) {
		var oRslt = dialog.store();
		this.aStrVariables[0] = oRslt["#ICFvW7rYU56MUEPWZ0ryi0#iaText"];
	},

	//
	description:
	{
	 name: "JavaScript-venster",
	 elements:
	[
		{
			type: "view",
			elements:
				[
					{
						type: "cluster",
						name: "Tekstwaarden",
						elements:
							[
								{
									type: "view",
									align_children: "align_row",
									elements:
									[
										{
											item_id: "lbl0",
											name: "Prefix:",
											type: "static_text",
										},
										{
											item_id: "#ICFvW7rYU56MUEPWZ0ryi0#iaText",
											type: "edit_text",
											width: 150,
										},
									]
								},
								]
					},
						{
						type: "ok_cancel",
					},
				]
		}
	]
	}
};
if (event.source.forReal && (event.source.stampName == "#ICFvW7rYU56MUEPWZ0ryi0")) {
	if (dlg.DoDialog() == "ok") {
		var aTextFieldNames = ["#ICFvW7rYU56MUEPWZ0ryi0#iaText", ];
		var tmpDate = new Date();
		for (var i = 0; i < aTextFieldNames.length; i++) {
			field = event.target.getField(aTextFieldNames[i]);
			if (app.pxceInfo!=undefined)
				field.value = util.expandMacros(dlg.aStrVariables[i], {oDate: tmpDate});
			else
				field.value = dlg.aStrVariables[i];
		}
	}
	else {
		var aFields = ["#ICFvW7rYU56MUEPWZ0ryi0#iaText", ];
		for (var i = 0; i < event.target.numFields; i++) {
			field = event.target.getField(aFields[i]);
			field.value = "Geannuleerd!";
		}
	}}
else {
	event.value = "001.";
}
Now I like to save the prefix part so I don't have to type that every time I'm placing a stamp.


Thanks in advance,

Greetz,
Bjørn
User avatar
Dimitar - PDF-XChange
Site Admin
Posts: 2661
Joined: Mon Jan 15, 2018 9:01 am

Re: Create dynamic stamp with prefix and counter

Post by Dimitar - PDF-XChange »

Hello Bjørn,

I think our Stamp Tool can help you achieve this:


https://help.pdf-xchange.com/pdfxe10/stamp-tool_ed.html


Regards.