12 Replies Latest reply on May 14, 2017 10:48 AM by sargums46564804

    Explain type: "ok" in code

    sargums46564804 Level 1

      Hi,

       

      I have 2 questions:

       

      1) I do not understand how something which looks like a button (see Image from Action Wizard form) shows up as a type: "ok" as shown below. I need to understand what a type of "ok" even means and why it is not a "button" as it is with the Skip and Cancel buttons.  I looked and cannot find an explanation anywhere, only check boxes, buttons, etc.

       

      2) Once I understand #1, how can I make it so that the user only has to click this "Apply Label" button once to execute the entire loop. Right now the user has to click on "Apply label" for every document open.  I copied what I think are relevant parts from the code (see Excerpts of Code below).

       

      Image from Action Wizard Form:

       

      Excerpts of Code (with relevant text in red):

       

       

                                       {

                                          type: "view",

                                          align_children: "align_top",

                                          alignment: "align_top",

                                          elements:

                                          [

                                              {

                                                  type: "ok",

                                                  ok_name: "Apply Label",

                                              },

                                              {

                                                  type: "button",

                                                  item_id: "Skip",

                                                  name: "Skip this Doc",

       

       

                                              },

                                              {

                                                  type: "button",

                                                  item_id: "Abrt",

                                                  name: "Cancel",

                                              },

       

      (continued)

      .

      .

      .

      .

      var DoNumActionDlg = app.trustedFunction(function()

      {

         app.beginPriv();

         return app.execDialog(global.DocNumAction);

       

       

      app.endPriv();

       

       

      });

       

       

          // Setup

      var oDoc = event.target;

      if(oDoc.xfa)

      {

         if(3 == app.alert(oDoc.documentFileName + ": is a LiveCycle Form, which cannot be labeled\n\n Do you want to continue processing files? (Pressing No will Abort the file processing)",1,2))

           event.rc = false;

      }

      else

       

       

          global.DocNumAction.bHidden = oDoc.hidden;

          if(!oDoc.hidden)

             global.DocNumAction.nCurPage = oDoc.pageNum;

          else

             global.DocNumAction.nCurPage = 0;

       

       

          global.DocNumAction.nNumPages = oDoc.numPages;

        

          global.DocNumAction.strFileName = oDoc.documentFileName;

       

       

       

       

         var cRtn = DoNumActionDlg();

         if("ok" == cRtn)

         {

             // Setup Initial Doc Number

             if(global.DocNumAction.bIncludePageNum)

                global.DocNumAction.nCurrentDocNum = Number(global.DocNumAction.strInitDocNum);

      console.println("Do " + oDoc.documentFileName);

       

       

             global.DoPlaceDocNumbers(oDoc);

       

       

       

       

            // Increment Doc Number if applicable

            if(global.DocNumAction.bIncludeDocNum)

            {

                global.DocNumAction.nCurrentDocNum++;

                global.DocNumAction.strInitDocNum = global.DocNumAction.nCurrentDocNum.toString();

       

       

            }

       

        }

       

       

        else if("Abrt" == cRtn)

       

       

           event.rc  = false;

       

       

      }

        • 1. Re: Explain type: "ok" in code
          try67 MVP & Adobe Community Professional

          1. In a dialog object an "ok" type field is simply a button that confirms that the user accepted the settings in the dialog.

          "ok_cancel" is a set of two buttons, one to accept the settings and one to dismiss them, and "ok_cancel_other" is a set of three buttons: OK, Cancel and a custom one. That's it.

           

          2. This question is not clear... I'm not seeing any loop in your code.

          • 2. Re: Explain type: "ok" in code
            Test Screen Name Most Valuable Participant

            What version of the Acrobat JavaScript API documentation are you using? I see "ok" documented with the other valid types for the dialog box elements property.

            • 3. Re: Explain type: "ok" in code
              Joel_Geraci Adobe Community Professional

              The generic "button" type can be used to trigger an event that runs a function that you define. The types "ok", "ok_cancel", and "ok_cancel_other" will dismiss the dialog and trigger the "commit" function and pass the button name that was pressed back the code that called the dialog. That said, you can certainly force a "button" to call the "Commit" function as well.  

              • 4. Re: Explain type: "ok" in code
                sargums46564804 Level 1

                HI,

                 

                Now I understand what the "ok" type field is.  Thx.

                Below is the loop.  How do I make it so the user can click "Apply Label" and it just will stay clicked for entire batch of documents.  Right now the user has to click it each time such that if there are 15 documents, they have to click "Apply Label" for each one.  Eventually I want to make it an option for them to decide if they want to go one by one (which allows them to change the label for a particular document) or just apply labels to all of them all at once.  In the mean time, I want to focus on the latter (labeling all of them all at once with the click of one button).

                 

                Here is loop:

                 

                // Start Labeling Loop

                     var nNumPages = nPgEnd - nPgStart + 1;

                     var nCurPgNum = nPgStart;

                 

                     for(var nPg=0;nPg<nNumPages;nPg++,nCurPgNum++,nPgTrgStart++)

                     {

                        // Create text Label

                        var strExample = global.DocNumAction.strLabelPrefix;

                        if(global.DocNumAction.bIncludeDocNum)

                           strExample += global.DocNumAction.nCurrentDocNum;

                 

                        if(global.DocNumAction.bIncludePageNum)

                        {

                           strExample += eval("'" + global.DocNumAction.strPageNumPrefix + "'") + (nCurPgNum + 1).toString();

                 

                        if(global.DocNumAction.bPageNumPostfix)

                          strExample += " of " + oOrigDoc.numPages;

                        }

                 

                        // Find Placement location on Page

                        // get basic params

                        var rcPage = oOrigDoc.getPageBox("Crop",nCurPgNum);

                        var mxToDefaultCoords = (new Matrix2D()).fromRotated(oOrigDoc,nCurPgNum);

                        var nPgRot = oOrigDoc.getPageRotation(nCurPgNum);

                 

                        var rcRot = [];

                        var nAlign;

                        var nMargX = Number(global.DocNumAction.nMarginX) * 72;

                        switch(global.DocNumAction.strHorzPos)

                        {

                           case"PosL":

                             strAlign = "left"; // Left Aligned Text

                             rcRot[0] = nMargX;

                             rcRot[2] = nMargX + nLabWidth;

                             break;

                           case"PosC":

                             strAlign = "center"; // Left Aligned Text

                             rcRot[0] = rcPage[2]/2 - nLabWidth/2;

                             rcRot[2] = rcPage[2]/2 + nLabWidth/2;

                             break;

                           case"PosR":

                             strAlign = "right"; // Left Aligned Text

                             rcRot[0] = rcPage[2] - nMargX - nLabWidth;

                             rcRot[2] = rcPage[2] - nMargX;

                             break;

                        }

                 

                        // Find number of lines

                        var nMargY = Number(global.DocNumAction.nMarginY) * 72;

                        var nLines = 1;

                        var oMtch = strExample.match(/(\n)/g);

                        if(oMtch)

                          nLines += oMtch.length;

                 

                        var bxHght = nLines * (nLabLineHeight + 1);

                 

                        switch(global.DocNumAction.strVertPos)

                        {

                           case"PosT":

                             rcRot[1] = rcPage[1] - nMargY - bxHght;

                             rcRot[3] = rcPage[1] - nMargY;

                             break;

                           case"PosB":

                             rcRot[1] = nMargY;

                             rcRot[3] = nMargY + bxHght;

                             break;

                        }

                 

                        var rectAnnot = mxToDefaultCoords.transform(rcRot);

                 

                       // Look for an existing annot and delete if it exists

                       var annot = oTrgDoc.getAnnot(nPgTrgStart,"DocNumberLabel");

                       if(annot)

                         annot.destroy();

                 

                       //  Create annotation

                       strExample = strExample.replace(/\r\n/g,"\r");

                       oTrgDoc.addAnnot({type:"FreeText",page:nPgTrgStart, rect:rectAnnot,

                                         rotate:nPgRot, width:0, fillColor:cBkCol,

                                         readOnly:global.DocNumAction.strBoxStateSel == "Lckd",

                                         richContents:[{textColor:["RGB",0,0,0],textSize:nLabLineHeight,

                                                        alignment:strAlign, text:strExample}],

                                         name:"DocNumberLabel"

                                      });

                 

                     } 

                 

                     // Flatten

                       oTrgDoc.flattenPages();

                 

                 

                 

                 

                 

                     // Save File

                     if(global.DocNumAction.bSaveWPostFx)

                     {

                         var cSavePath = oOrigDoc.path.replace(/\/[^\/]+$/,"/");

                 

                 

                         var cDocPrefix;

                         cDocPrefix = global.DocNumAction.strLabelPrefix;

                 

                 

                        cSavePath += global.DocNumAction.strSavePrefix;

                 

                 

                //      Document number as prefix

                       

                      

                       if(global.DocNumAction.strDocNumInName == "DnPr")

                        {

                 

                 

                            if(global.DocNumAction.bIncludeDocNum)

                                       

                            cSavePath += global.DocNumAction.nCurrentDocNum

                            cSavePath += "_";

                        }

                        

                        cSavePath += oOrigDoc.documentFileName.replace(/\.pdf/,"");

                       

                 

                 

                 

                        //Document number as prostfix

                        if(global.DocNumAction.strDocNumInName == "DnFx")

                        {

                          

                           if(global.DocNumAction.bIncludeDocNum)

                             cSavePath += global.DocNumAction.nCurrentDocNum;

                        }

                 

                 

                        cSavePath += ".pdf";

                 

                 

                        oTrgDoc.saveAs(cSavePath);

                     }

                 

                     app.endPriv();

                 

                 

                 

                  });

                      

                }

                 

                 

                 

                 

                 

                var DoNumActionDlg = app.trustedFunction(function()

                {

                   app.beginPriv();

                   return app.execDialog(global.DocNumAction);

                 

                 

                app.endPriv();

                 

                 

                 

                 

                 

                 

                 

                });

                 

                 

                    // Setup

                var oDoc = event.target;

                if(oDoc.xfa)

                {

                   if(3 == app.alert(oDoc.documentFileName + ": is a LiveCycle Form, which cannot be labeled\n\n Do you want to continue processing files? (Pressing No will Abort the file processing)",1,2))

                     event.rc = false;

                }

                else

                 

                 

                    global.DocNumAction.bHidden = oDoc.hidden;

                    if(!oDoc.hidden)

                       global.DocNumAction.nCurPage = oDoc.pageNum;

                    else

                       global.DocNumAction.nCurPage = 0;

                 

                 

                    global.DocNumAction.nNumPages = oDoc.numPages;

                  

                    global.DocNumAction.strFileName = oDoc.documentFileName;

                 

                 

                 

                 

                   var cRtn = DoNumActionDlg();

                   if("ok" == cRtn)

                   {

                       // Setup Initial Doc Number

                       if(global.DocNumAction.bIncludePageNum)

                          global.DocNumAction.nCurrentDocNum = Number(global.DocNumAction.strInitDocNum);

                console.println("Do " + oDoc.documentFileName);

                 

                 

                       global.DoPlaceDocNumbers(oDoc);

                 

                 

                 

                 

                      // Increment Doc Number if applicable

                      if(global.DocNumAction.bIncludeDocNum)

                      {

                          global.DocNumAction.nCurrentDocNum++;

                          global.DocNumAction.strInitDocNum = global.DocNumAction.nCurrentDocNum.toString();

                 

                 

                      }

                 

                  }

                 

                 

                  else if("Abrt" == cRtn)

                 

                 

                     event.rc  = false;

                 

                 

                }

                • 5. Re: Explain type: "ok" in code
                  try67 MVP & Adobe Community Professional

                  This code is incomplete, and anyway it's too long for me to go over it in detail...

                  If the issue is that the dialog appears for each page then the solution is to call it once, before the pages loop, and then use the values from it in your loop. That way it will only appear one time.

                  • 6. Re: Explain type: "ok" in code
                    Bernd Alheit Adobe Community Professional & MVP

                    Display the dialog only once.

                    • 7. Re: Explain type: "ok" in code
                      sargums46564804 Level 1

                      Yes, I realized this morning that it makes more sense to take the dialog out of the loop than to try to make the button stay active.  Your remarks echo this.  I am playing around with it and making progress.  Thanks.

                      • 8. Re: Explain type: "ok" in code
                        sargums46564804 Level 1

                        I just figured out that the for loop I was referring to is only applicable to the pages within the active pdf file, not the multiple pdf files:

                         

                        // Start Labeling Loop

                            var nNumPages = nPgEnd - nPgStart + 1;

                            var nCurPgNum = nPgStart;

                         

                            for(var nPg=0;nPg<nNumPages;nPg++,nCurPgNum++,nPgTrgStart++)

                            {

                                // Create text Label

                                var strExample = global.DocNumAction.strLabelPrefix;

                                if(global.DocNumAction.bIncludeDocNum)

                                  strExample += global.DocNumAction.nCurrentDocNum;

                         

                                if(global.DocNumAction.bIncludePageNum)

                                {

                                  strExample += eval("'" + global.DocNumAction.strPageNumPrefix + "'") + (nCurPgNum + 1).toString();

                         

                                if(global.DocNumAction.bPageNumPostfix)

                                  strExample += " of " + oOrigDoc.numPages;

                                }

                        When the user hits the "Apply Label" button (type: "ok"), it opens the next pdf in the batch and re- initiates the entire labeling action.  It appearshis is not based on a for loop within the program for the pdf files but simply b/c this is a javascript within an action wizard and it cycles through all the pdf which were selected to apply the code to.

                         

                        Hence, I am back to my 2nd question, how can I keep the type:"ok" button active so user does not have to click on it to go through all the pdf documents?

                        • 9. Re: Explain type: "ok" in code
                          try67 MVP & Adobe Community Professional

                          You're looking for solutions in the wrong places.

                          If you want to use the same values for all pages in all files then collect

                          them before running the Action, save them into a global variable and then

                          use them in your Action.

                          • 10. Re: Explain type: "ok" in code
                            sargums46564804 Level 1

                            Hi,

                             

                            I do not think I can do what you are suggesting.  This is a batch labeling action wizard which has 3 steps (see below).  For each pdf, it removes containers (Preflight), shrinks the page (Header&Footer), and adds a label (Execute JavaScript).  I am realizing I cannot label all the files continuously in the JavaScript after clicking "Apply Label" for several reasons:

                            1. It is only executing the JavaScript on one pdf at a time and once done, it starts on the next pdf with a Preflight, Header & Footer, etc.:

                                // Setup

                            var oDoc = event.target;              <------------------------------------This is the focus on the individual pdf file

                            if(oDoc.xfa)

                            {

                               if(3 == app.alert(oDoc.documentFileName + ": is a LiveCycle Form, which cannot be labeled\n\n Do you want to continue processing files? (Pressing No will Abort the file processing)",1,2))

                                 event.rc = false;

                            }

                            else

                             

                            global.DocNumAction.bHidden = oDoc.hidden;

                            if(!oDoc.hidden)

                            global.DocNumAction.nCurPage = oDoc.pageNum;

                                else

                            global.DocNumAction.nCurPage = 0;

                            global.DocNumAction.nNumPages = oDoc.numPages;

                            global.DocNumAction.strFileName = oDoc.documentFileName;

                               var cRtn = DoNumActionDlg();        <--------------------------------------------DoNumActionDlg initiates dialoguen to enter parameters of label and evokes the overall action

                            if("ok" == cRtn)                                   <--------------------------------------------This is the "Apply Label"

                               {

                                   // Setup Initial Doc Number

                            if(global.DocNumAction.bIncludePageNum)

                            global.DocNumAction.nCurrentDocNum = Number(global.DocNumAction.strInitDocNum);

                            console.println("Do " + oDoc.documentFileName);

                             

                                   global.DoPlaceDocNumbers(oDoc);

                             

                                  // Increment Doc Number if applicable

                            if(global.DocNumAction.bIncludeDocNum)

                                  {

                            global.DocNumAction.nCurrentDocNum++;

                            global.DocNumAction.strInitDocNum = global.DocNumAction.nCurrentDocNum.toString();

                                  }

                              }

                              else if("Abrt" == cRtn)

                            event.rc  = false;

                            }

                             

                            2. Even if I could label all the pdf's within the JavaScript after clicking apply label, it would then not perform the Preflight and Header & Footer to each individual pdf

                             

                            Is there a work around?  This is why I am asking if there is a way to "trick" the program into thinking the user is clicking "Apply Label" each time so each pdf can still have all 3 steps of the action wizard without the manual effort of clicking "Apply Label" each time.  For 300 pdf documents, that's a lot of clicking. Thanks for your patience.

                             

                             

                            Excerpt from dialogue where have to click "Apply Label":

                            • 11. Re: Explain type: "ok" in code
                              try67 MVP & Adobe Community Professional

                              You can do it using the method I described. Read my reply more carefully, please.

                              • 12. Re: Explain type: "ok" in code
                                sargums46564804 Level 1

                                Hi

                                 

                                I do not always understand the posts b/c I am quite a novice. I have simply tweaked the code here and there but that is all.  I did download the API ref like you suggested and it has helped me understand some things.

                                 

                                I am not quite sure how to do what you are saying. The label content would be the same for all the files with the exception that the document # is stepped up so pdf 1 would say doc1, pdf 2 wiuld say doc 2, etc. in the label.

                                 

                                I am encouraged you are saying there is a way to simply click Apply once and it labels all at the same time, and steps up the doc # in the label too, and applies the prefkight and header/footer to each pdf but have no idea how. Any guidance would be helpful.