Skip to main content
Participating Frequently
April 9, 2025
Question

Dynamic Stamp with auto Popup for data entry

  • April 9, 2025
  • 2 replies
  • 2174 views

Dear Adobe Community,

I’m trying to create a custom stamp that, when added to a document, automatically shows a popup dialog. This dialog should first ask the user (a) how many rows need to be filled, and then (b) display input fields for each row where the user can enter data separated by semicolons. These values are then parsed and placed into individual fields.

This works perfectly when I use the JavaScript in a regular PDF form. However, as soon as I turn it into a dynamic stamp, the input dialog no longer appears.

 

var maxRows = 5;

var zeilenStr = app.response({
    cQuestion: "Wie viele Zeilen möchten Sie befüllen? (1–5)",
    cTitle: "Zeilenanzahl eingeben",
    cDefault: "3"
});

var anzahl = parseInt(zeilenStr);
if (isNaN(anzahl) || anzahl < 1 || anzahl > maxRows) {
    app.alert("Ungültige Anzahl. Bitte zwischen 1 und 5 angeben.");
} else {
    for (var i = 1; i <= anzahl; i++) {
        var eingabe = app.response({
            cQuestion: "Werte für Zeile " + i + " eingeben (mit Semikolon getrennt):\nMontant;Compte;Analytique;Type activite",
            cTitle: "Zeile " + i,
            cDefault: ""
        });

        if (eingabe) {
            var werte = eingabe.split(";");

            if (werte.length > 0) this.getField("MontantRow" + i).value = werte[0];
            if (werte.length > 1) this.getField("CompteRow" + i).value = werte[1];
            if (werte.length > 2) this.getField("AnalytiqueRow" + i).value = werte[2];
            if (werte.length > 3) this.getField("Type activiteRow" + i).value = werte[3];
        }
    }
}

 

Thank you very much for your help!
Regards
Kremer

2 replies

PDF Automation Station
Community Expert
Community Expert
April 9, 2025
try67
Community Expert
Community Expert
April 9, 2025

Please search the forum. This issue was discussed here plenty of times in the past, including full tutorials, code examples and even a book written on it!

kremerSKBAuthor
Participating Frequently
April 9, 2025

Hello,
I've already read through several posts and tried many different approaches, but unfortunately, the popup never appears when using the stamp.

Attached is a sample PDF with the stamp. All form fields are properly defined, and there's a hidden field containing the JavaScript code. The stamp name is also set correctly.

Thank you in advance!

Thom Parker
Community Expert
Community Expert
April 9, 2025

The popup appears when I installed your stamp. So it works, but the dialog has some problems. 

First, it needs a an "Ok" button. That's the only way to exit the dialog and run the commit code. 

Next, the keyword "this", in any function(method) in any object, is a pointer to the object itself. So, this.getField doesn't work inside the dialog object. The code needs to either include pointer to the current doc as a member of the dialog object, or placing data into fields needs to be done outside the dialog. 

And finally, the "item_id" of a field in the dialog object can only be 4 characters. 

 

I would suggest getting the dialog code to work first, before including it into the stamp. 

 

Here's a tool for creating dialogs. 

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

 

 

 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often