Skip to main content
Participating Frequently
April 9, 2025
Question

Dynamic Stamp with auto Popup for data entry

  • April 9, 2025
  • 2 replies
  • 2124 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
Adobe Expert
April 9, 2025
try67
Adobe 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
Adobe Expert
April 17, 2025

Hello

 

thank you very much @Thom Parker for the tip. this worked.
I now just have to figure out why the OK an Cancel label are disappearing after chosing the first dropdown 🙂

 

 description: {
            name: "Stempel mit Dropdown",
            elements: (function () {
                var rows = [];

                for (var i = 1; i <= 5; i++) {
                    rows.push({
                        type: "view",
                        orientation: "row",
                        align_children: "align_top",
                        elements: [
                            {
                                type: "view",
                                orientation: "column",
                                align_children: "align_left",
                                elements: [
                                    (i === 1 ? { type: "static_text", name: "Type" } : {}),
                                    {
                                        item_id: "Typ" + i,
                                        type: "popup",
                                        char_width: 7,
                                        items: [
                                            { name: "-" },
                                            { name: "Loc" },
                                            { name: "Constr." },
                                            { name: "Infra." },
                                            { name: "Refact." }
                                        ]
                                    }
                                ]
                            },
                            {
                                type: "view",
                                orientation: "column",
                                align_children: "align_left",
                                elements: [
                                    (i === 1 ? { type: "static_text", name: "Compte" } : {}),
                                    {
                                        item_id: "Com" + i,
                                        type: "popup",
                                        char_width: 9,
                                        items: [
                                            { name: "-" }
                                        ]
                                    }
                                ]
                            },
                            {
                                type: "view",
                                orientation: "column",
                                align_children: "align_left",
                                elements: [
                                    (i === 1 ? { type: "static_text", name: "Analytique" } : {}),
                                    {
                                        item_id: "Ana" + i,
                                        type: "edit_text",
                                        char_width: 25
                                    }
                                ]
                            },
                            {
                                type: "view",
                                orientation: "column",
                                align_children: "align_left",
                                elements: [
                                    (i === 1 ? { type: "static_text", name: "Montant" } : {}),
                                    {
                                        item_id: "Mon" + i,
                                        type: "edit_text",
                                        char_width: 9
                                    }
                                ]
                            }
                        ]
                    });
                }

                rows.push({
                    type: "ok_cancel",
                    ok_name: "OK",
                    cancel_name: "Abbrechen"
                });

                return rows;
            })()
        }
    };

    function updateCompte(dialog, index) {
        var store = dialog.store();
        var selectedType = getSelectedValue(store["Typ" + index]);

        var comptes = compteOptions[selectedType] || ["-"];
        var compteValues = {};
        comptes.forEach(function(val, idx) {
            compteValues[val] = (idx === 0) ? 1 : 0;
        });

        store["Com" + index] = compteValues;
        dialog.load(store);
    }

Don't load the entire "store" object. Instead load only the specific field of interest. 

 

var oInit = {};

oInit["Com"+index] = compteValues;

dialog.load(oInit);

 

 

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