• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

dialog box in a secured document

Participant ,
Feb 14, 2021 Feb 14, 2021

Copy link to clipboard

Copied

I have a pdfa where javaskrypt starts when a page is opened.
It's a simple dialog. Works correctly. But when I password-protect my PDF, I get the following message in the console:
NotAllowedError: Security settings prevent access to this property or method.
Doc.addField: 3: Page undefined: Open
How to change the permissions to make the script run?

// ### if frame "sz3" not exist, create it
if (!this.getField("sz3")) {
    var sz3 = this.addField("sz3", "text", 0, [10, 720, 70, 700]);
    sz3.password = false;
    sz3.textSize = 8;
    sz3.alignment = "center";
    sz3.value = "ustaw hasło";

    var jestHaslo = "";
    // ### Wyświetlenie okno dialogowego do utworzenia naszego HASŁA
    var dialog1 = {
        initialize: function (dialog) {
            var myPass = "";
            var todayDate = dialog.store()["date"];
            todayDate = util.printd("mmmm dd, yyyy", new Date());
            dialog.load({
                "date": todayDate
            });
        },
        commit: function (dialog) { // called when OK pressed
            var results = dialog.store();
            sz3.value = results["pass"];
            sz3.readonly = true;
            sz3.display = display.hidden;
            jestHaslo = "T";
        },
        ok: function (dialog) {},
        cancel: function (dialog) {
            sz3.value = "";
            sz3.readonly = true;
            sz3.display = display.hidden;
            jestHaslo = "N";
        },
        description: {
            name: "Personal Data", // Dialog box title
            align_children: "align_left",
            width: 350,
            height: 200,
            elements: [
                {
                    type: "view",
                    name: "Your Name",
                    align_children: "align_left",
                    elements: [
                        {
                            type: "static_text",
                            name: "Date: ",
                            char_width: 25,
                            item_id: "date"
},
                        {
                            type: "static_text",
                            name: "xxx",
                            char_width: 35,
                            height: 60
},
                        {
                            item_id: "pass",
                            type: "edit_text",
                            alignment: "align_center",
                            width: 100,
                            height: 20
},
                        {
                            type: "static_text",
                            name: "xxx",
                            bold: true,
                            char_width: 35,
                            height: 30
}
]
},
                {
                    alignment: "align_left",
                    type: "ok_cancel",
                    ok_name: "Ustawiam",
                    cancel_name: "Rezygnuję"
}
]
        }
    };
    app.execDialog(dialog1);
} else {
    var sz3 = this.getField("sz3");
    sz3.textColor = color.white;
    sz3.password = true;
    sz3.readonly = true;
    sz3.display = display.hidden;
    var k1 = String(this.getField("K1").value);
    if (k1 != "") {
        for (var x = 1; x <= 14; x++) {
            this.getField(String(x)).readonly = true;
        }
         this.getField("3a").readonly = true;
         this.getField("3b").readonly = true;
         this.getField("4a").readonly = true;
         this.getField("4b").readonly = true;
         this.getField("8a").readonly = true;
         this.getField("8b").readonly = true;
         this.getField("11a").readonly = true;
         this.getField("11b").readonly = true;
         this.getField("14a").readonly = true;
         this.getField("14b").readonly = true;
    }
}
TOPICS
Edit and convert PDFs , How to , JavaScript , PDF forms

Views

443

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Participant , Feb 15, 2021 Feb 15, 2021

I solved the problem 🙂
I changed the scope of restrictions when securing a document.
now frames can be completed, but the user does not have access to edit form fields 🙂

Votes

Translate

Translate
LEGEND ,
Feb 14, 2021 Feb 14, 2021

Copy link to clipboard

Copied

Neither JavaScript nor encryption is allowed in PDF/A.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 14, 2021 Feb 14, 2021

Copy link to clipboard

Copied

In case you didn't mean PDF/A, the problem you're seeing is that the security you applied does not allow changing the document, which is what addField would do if allowed. It would be helpful if you posted a screen shot after you select: File > Properties > Security

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 14, 2021 Feb 14, 2021

Copy link to clipboard

Copied

When you want add fields you must allow change of the document.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 15, 2021 Feb 15, 2021

Copy link to clipboard

Copied

Thanks for the hint. I created a frame directly in the document and hid it. The dialog box no longer contains it, it only references it. Now everything works fine 🙂

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 15, 2021 Feb 15, 2021

Copy link to clipboard

Copied

However, not everything 😞
NotAllowedError: Security settings deny access to this property or method. Error () @: 0
The dialog that opens after opening the PDF should enter my key in the sz3 frame.
I enter the key here:
item_id: "pass",
type: "edit_text",
alignment: "align_center",
width: 100,
height: 20

How to set the privileges of the sz3 frame so that this key is entered into it?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 15, 2021 Feb 15, 2021

Copy link to clipboard

Copied

this is the javascript run when pdfa is opened

var sz3 = this.getField("sz3");

if (this.getField("sz3").value == "") {
    sz3.readonly = false;
    sz3.textSize = 8;
    sz3.alignment = "center";

    var jestHaslo = "";
    var dialog1 = {
        initialize: function (dialog) {
            var myPass = "";
            var todayDate = dialog.store()["date"];
            todayDate = util.printd("mmmm dd, yyyy", new Date());
            dialog.load({
                "date": todayDate
            });
        },
        commit: function (dialog) { // called when OK pressed
            var results = dialog.store();
console.println("Twoje hasło to: " + results["pass"]);
            sz3.value = results["pass"];
            sz3.readonly = true;
            sz3.display = display.hidden;
            jestHaslo = "T";
console.println("sz3 pass: " + sz3.value);
        },
        ok: function (dialog) {},
        cancel: function (dialog) {
            sz3.value = "";
            sz3.readonly = false;
            sz3.display = display.hidden;
            jestHaslo = "N";
        },
        description: {
            name: "Personal Data", // Dialog box title
            align_children: "align_left",
            width: 350,
            height: 200,
            elements: [
                {
                    type: "view",
                    name: "Your Name",
                    align_children: "align_left",
                    elements: [
                        {
                            type: "static_text",
                            name: "Date: ",
                            char_width: 25,
                            item_id: "date"
},
                        {
                            type: "static_text",
                            name: "Można zablokować zliczanie punktów na karcie odpowiedzi, aby uniemożliwić \ruczniom odkrycie poprawnych odpowiedzi w zadaniach zamkniętych. \rW tym celu ustaw hasło i potwierdź przyciskiem [Ustawiam]. \rWpisanie hasła w pole sumy punktów przywraca automatyczne zliczanie punktów.",
                            char_width: 35,
                            height: 60
},
                        {
                            item_id: "pass",
                            type: "edit_text",
                            alignment: "align_center",
                            width: 100,
                            height: 20
},
                        {
                            type: "static_text",
                            name: "Rekomendowane jest zapisanie dokumentu z hasłem pod nową nazwą, \rnp: [nazwa arkusza]_ucznia.pdf itp.",
                            bold: true,
                            char_width: 35,
                            height: 30
}
]
},
                {
                    alignment: "align_left",
                    type: "ok_cancel",
                    ok_name: "Ustawiam",
                    cancel_name: "Rezygnuję"
}
]
        }
    };
    app.execDialog(dialog1);
} else {
    var k1 = String(this.getField("K1").value);
    if (k1 != "") {
        for (var x = 1; x <= 14; x++) {
            this.getField(String(x)).readonly = true;
        }
         this.getField("3a").readonly = true;
         this.getField("3b").readonly = true;
         this.getField("4a").readonly = true;
         this.getField("4b").readonly = true;
         this.getField("8a").readonly = true;
         this.getField("8b").readonly = true;
         this.getField("11a").readonly = true;
         this.getField("11b").readonly = true;
         this.getField("14a").readonly = true;
         this.getField("14b").readonly = true;
    }
}

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 15, 2021 Feb 15, 2021

Copy link to clipboard

Copied

LATEST

I solved the problem 🙂
I changed the scope of restrictions when securing a document.
now frames can be completed, but the user does not have access to edit form fields 🙂

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines