Skip to main content
Participant
September 5, 2023
Question

Upload pdf function and button not working

  • September 5, 2023
  • 1 reply
  • 445 views

When i click on add pdf button nothing happenig and then click on ok it giving me this error : 
NotAllowedError: Security settings prevent access to this property or method.
App.browseForDoc:103:Menu Upload:Exec

I want on click of Add file i can add pdf file from my file explrer and click on ok i want to send the pdf in databse wih rest api . is it possible ? pls look into overall i want to add the pdf also use the pdf  . 
here is the code : 

function showUploadDialog() {
  // Dialog Definition
  var oDlg = {
    usnm: {
      // Define a nested object for usnm
      flnm: "",
      vers: "",
      lfnu: "",
      lccn: "",
    },

    initialize: function (dialog) {
      dialog.load(this.usnm); // Load the nested object directly
    },
    commit: function (dialog) {
      var data = dialog.store();
      this.usnm.flnm = data.flnm; // Access the nested object's properties
      this.usnm.vers = data.vers;
      this.usnm.lfnu = data.lfnu;
      this.usnm.lccn = data.lccn;
    },
    description: {
      name: "Test Dialog",
      elements: [
        {
          type: "view",
          elements: [
            { name: "Filename:", type: "static_text" },
            { item_id: "flnm", type: "edit_text", char_width: 30 }, // Use "flnm" instead of "usnm.flnm"
          ],
        },
        {
          type: "view",
          elements: [
            // Add a view for the vers field
            { name: "Version:", type: "static_text" },
            { item_id: "vers", type: "edit_text", char_width: 30 }, // Use "vers" instead of "usnm.vers"
          ],
        },
        {
          type: "view",
          elements: [
            // Add a view for the lfnu field
            { name: "LegalEdge File Number:", type: "static_text" },
            { item_id: "lfnu", type: "edit_text", char_width: 30 }, // Use "lfnu" instead of "usnm.lfnu"
          ],
        },
        {
          type: "view",
          elements: [
            // Add a view for the lfnu field
            { name: "LegalEdge Court Case Number:", type: "static_text" },
            { item_id: "lccn", type: "edit_text", char_width: 30 }, // Use "lfnu" instead of "usnm.lfnu"
            { type: "button", name: "Add PDF", item_id: "add_pdf_button" }, // Add a button to add PDF files
            { type: "ok_cancel" },
          ],
        },
      ],
    },
  };

  // Dialog Activation
  oDlg.usnm.flnm = "Larry";
  oDlg.usnm.vers = "1.0";
  oDlg.usnm.lfnu = "Sample";
  oDlg.usnm.lccn = "Sample2";

  var response = app.execDialog(oDlg);

  // Handle the PDF file attachment functionality when the "Add PDF" button is clicked
  if (response === "ok") {
    var attachmentCounter = 0;

    do {
      attachmentCounter++;
      var fileAttachment = this.addAnnot({
        page: 0,
        type: "FileAttachment",
        rect: [100, 100, 200, 200],
        contents: "Attached file " + attachmentCounter,
        cAttachmentPath: app.browseForDoc(), // Use app.browseForDoc() to select PDF files
      });

      response = app.alert("Add another file?", 2, 2);
    } while (response === 4);

    // Handle file attachments here if needed

    // Close the dialog or perform other actions as necessary
  }
}
This topic has been closed for replies.

1 reply

Thom Parker
Community Expert
Community Expert
September 5, 2023
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often