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

Cant add pdf as attachment

Community Beginner ,
Sep 05, 2023 Sep 05, 2023

I want after click on add pdfbutton it shoul dopen a file explorer so i can attach a file  ,pls help me , i ll given to u my file if u can help me so u can easly resolve my problem 

function showUploadDialog() {
  // Dialog Definition
  var oDlg = {
    usnm: {
      flnm: "",
      vers: "",
      lfnu: "",
      lccn: "",
    },
    initialize: function (dialog) {
      dialog.load(this.usnm);
    },
    commit: function (dialog) {
      var data = dialog.store();
      this.usnm.flnm = data.flnm;
      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 },
          ],
        },
        {
          type: "view",
          elements: [
            { name: "Version:", type: "static_text" },
            { item_id: "vers", type: "edit_text", char_width: 30 },
          ],
        },
        {
          type: "view",
          elements: [
            { name: "LegalEdge File Number:", type: "static_text" },
            { item_id: "lfnu", type: "edit_text", char_width: 30 },
          ],
        },
        {
          type: "view",
          elements: [
            { name: "LegalEdge Court Case Number:", type: "static_text" },
            { item_id: "lccn", type: "edit_text", char_width: 30 },
            { type: "button", name: "Add PDF", item_id: "add_pdf_button" },
            { 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);

  // Attach a click event listener to the "Add PDF" button
  if (response === "ok") {
    var addPdfButton = oDlg.description.elements[3].elements[2]; // Access the "Add PDF" button directly

    addPdfButton.onClick = function () {
      addPdfButtonClicked = true; // Set the flag
      openFileExplorerForPdf(); // Call the function to open the file explorer
    };
  }
}

// Define a global variable to indicate whether the "Add PDF" button was clicked
var addPdfButtonClicked = false;

// Function to open the file explorer dialog
function openFileExplorerForPdf() {
  if (addPdfButtonClicked) {
    var cAttachmentPath = app.browseForDoc();
    if (cAttachmentPath) {
      var attachmentCounter = 0;
      attachmentCounter++;
      var fileAttachment = this.addAnnot({
        page: 0,
        type: "FileAttachment",
        rect: [100, 100, 200, 200],
        contents: "Attached file " + attachmentCounter,
        cAttachmentPath: cAttachmentPath,
      });
    }
    addPdfButtonClicked = false; // Reset the flag
    console.println("ssuuuuiiiiiiiiiiiiii");
  }
}
TOPICS
Cancel subscription , Comment review and collaborate Experiment , Crash or freeze , Create PDFs , Edit and convert PDFs , General troubleshooting , How to , Install update and subscribe to Acrobat , JavaScript , Modern Acrobat , PDF , PDF forms , Print and prepress , Rich media and 3D , Scan documents and OCR , Security digital signatures and esignatures , Standards and accessibility
228
Translate
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 ,
Sep 05, 2023 Sep 05, 2023
LATEST

The way to develop and debug code is to start simple.  Isolate the bits you are not sure about and figure out those bits before incorporating them into a larger script. 

For example. In the code above, the custom dialog is irrelavant. Why is it there? 

Why is any of the code there? Is the "app.browseForDoc()" working as expected? Or is it adding the attachment that is the problem?  Are you getting an error, or is it just not working. 

Please test only the code that isn't working. Post that, and tell us exactly what isn't working. 

 

 

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

Translate
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