23 Replies Latest reply on Jan 17, 2012 1:11 PM by Bernd Alheit

    Creating redaction button

    xhawk

      I am trying to create a button to redact predetermined areas from a document. Here is what I have so far.

       

      // if the application is Adobe Acrobat...then create the redaction button

          if(app.viewerType == "Exchange-Pro") {

       

              app.trustedFunction(customSilentPrint);

       

              app.addToolButton({

                  cName: "AddMyRedacts",

                  cExec: "AddMyRedacts()",

                  cTooltext: "Redact",

                  cLabel: "Redact",

                  cEnable: "event.rc = (app.doc != null)" });

          }

       

      // Quads for the different Redaction areas

       

      // Template 1 Quads

      var qdPage1Box1 =  [[50.84193420410156, 632.2653198242188, 322.8841857910156, 632.2653198242188, 50.84193420410156, 469.1158142089844, 322.8841857910156, 469.1158142089844]];

      var qdPage1Box2 = [[49.70368957519531, 440.6595764160156, 321.7459411621094, 440.6595764160156, 49.70368957519531, 277.51007080078125, 321.7459411621094, 277.51007080078125]];

      var qdPage1Box3 = [[50.083099365234375, 249.81263732910156, 322.1253356933594, 249.81263732910156, 50.083099365234375, 86.66313171386719, 322.1253356933594, 86.66313171386719]];

      var qdPage1Box4 = [[328.954833984375, 593.5648193359375, 592.64990234375, 593.5648193359375, 328.954833984375, 503.2633972167969, 592.64990234375, 503.2633972167969]];

      var qdPage1Box5 = [[329.7136535644531, 402.3385009765625, 593.40869140625, 402.3385009765625, 329.7136535644531, 312.0370788574219, 593.40869140625, 312.0370788574219]];

      var qdPage1Box6 = [[328.19598388671875, 211.49156188964844, 591.8909912109375, 211.49156188964844, 328.19598388671875, 121.19013977050781, 591.8909912109375, 121.19013977050781]];

       

      function AddMyRedacts(quadList){

       

              // explicitly raise privileges

              app.beginPriv();

      {

        for(var pg=0; pg<this.numPages; pg++)

        {

          for(var i=0; i<quadList.length; i++)

          {

            this.addAnnot({type:"Redact", page:0, quads:quadList[i],

                           overlayText: " ",

                           alignment: 1, // center alignment

                           repeat:true

                          });

          }

        }

      }

       

      // end explicit privileges

              app.endPriv();

      }

       

      ////////////

      // Applying the redactions

       

      AddMyRedacts([qdPage1Box1, qdPage1Box2, qdPage1Box3,

                    qdPage1Box4, qdPage1Box5, qdPage1Box6]

                  );

      this.applyRedactions({ bKeepMarks: false,

                             bShowConfirmation: true,

                             cProgText: "Itís going away"

                           });

       

      I am not sure how to proceed. I can't get the button to appear in adobe. Any help would be much appreciated. Thank you.

       

      -xhawk

        • 1. Re: Creating redaction button
          George_Johnson MVP & Adobe Community Professional

          What is this line supposed to do:

           

          app.trustedFunction(customSilentPrint);

           

          and as a test, what happens if you remove it?

           

          Also, where exactly did you place this code? Most of it needs to be in a folder-level JavaScript file.

          • 2. Re: Creating redaction button
            try67 MVP & Adobe Community Professional

            In addition to George's comments, you should also check the JS console for errors.

             

            I'm seeing a logical problem with your code. You're calling AddMyRedacts() without specifying the quadsList parameter. This should cause an error in your loop.

            Another issue, which shouldn't cause it to fail, but just doesn't make sense, is that you're using a loop to go over all the pages of the document, but in your addAnnot command you hard-coded the page number to 0.

            • 3. Re: Creating redaction button
              xhawk Level 1

              I had gotten that line from some Acrobat documentation example of creating a button. Removing it (as far as I can tell) has had no effect. And yes, the code needs to be in a folder-level JavaScript file, which is what I have done.

              • 4. Re: Creating redaction button
                xhawk Level 1

                Thats the thing. I had created the redaction code and got it to work in the console without errors. I wanted to create a button to simplify the process for the people who will be eventually using this. I also realize that that doesn't make since but I am just doing the first page of the documents for now and will adapt it later for the rest of the pages. I'm now getting an error that says:

                 

                redeclaration of const AddMyRedacts

                25:Console:Exec

                 

                Here is my updated code:

                 

                // if the application is Adobe Acrobat...then create the redaction button

                    if(app.viewerType == "Exchange-Pro") {

                 

                app.addToolButton({

                            cName: "AddMyRedacts",

                            cExec: "AddMyRedacts()",

                            cTooltext: "Redact",

                            cLabel: "Redact",

                            cEnable: "event.rc = (app.doc != null)" });

                    }

                 

                // Quads for the different Redaction areas

                 

                // Template 1 Quads

                var qdPage1Box1 =  [[50.84193420410156, 632.2653198242188, 322.8841857910156, 632.2653198242188, 50.84193420410156, 469.1158142089844, 322.8841857910156, 469.1158142089844]];

                var qdPage1Box2 = [[49.70368957519531, 440.6595764160156, 321.7459411621094, 440.6595764160156, 49.70368957519531, 277.51007080078125, 321.7459411621094, 277.51007080078125]];

                var qdPage1Box3 = [[50.083099365234375, 249.81263732910156, 322.1253356933594, 249.81263732910156, 50.083099365234375, 86.66313171386719, 322.1253356933594, 86.66313171386719]];

                var qdPage1Box4 = [[328.954833984375, 593.5648193359375, 592.64990234375, 593.5648193359375, 328.954833984375, 503.2633972167969, 592.64990234375, 503.2633972167969]];

                var qdPage1Box5 = [[329.7136535644531, 402.3385009765625, 593.40869140625, 402.3385009765625, 329.7136535644531, 312.0370788574219, 593.40869140625, 312.0370788574219]];

                var qdPage1Box6 = [[328.19598388671875, 211.49156188964844, 591.8909912109375, 211.49156188964844, 328.19598388671875, 121.19013977050781, 591.8909912109375, 121.19013977050781]];

                 

                var quadList = [[qdPage1Box1, qdPage1Box2, qdPage1Box3, qdPage1Box4, qdPage1Box5, qdPage1Box6]];

                 

                function AddMyRedacts(quadList){

                 

                        // explicitly raise privileges

                //        app.beginPriv();

                {

                  for(var pg=0; pg<this.numPages; pg++)

                  {

                    for(var i=0; i<quadList.length; i++)

                    {

                      this.addAnnot({type:"Redact", page:0, quads:quadList[i],

                                     overlayText: " ",

                                     alignment: 1, // center alignment

                                     repeat:true

                                    });

                    }

                  }

                }

                 

                ////////////

                // Applying the redactions

                 

                AddMyRedacts([qdPage1Box1, qdPage1Box2, qdPage1Box3,

                              qdPage1Box4, qdPage1Box5, qdPage1Box6]

                            );

                this.applyRedactions({ bKeepMarks: false,

                                       bShowConfirmation: true,

                                       cProgText: "Itís going away"

                                     });

                // end explicit privileges

                //        app.endPriv();

                }

                • 5. Re: Creating redaction button
                  gkaiseril MVP & Adobe Community Professional

                  With one of the updates to Acrobat X there has been a change in were trusted functions are located for Acrobat 10.1.1 on.

                   

                  User JavaScript Changes for 10.1.1 (Acrobat | Reader)

                   

                  http://kb2.adobe.com/cps/915/cpsid_91534.html

                  • 6. Re: Creating redaction button
                    try67 MVP & Adobe Community Professional

                    The error "redeclaration of const AddMyRedacts" means you either have

                    multiple copies of the same script, or you've declared two functions with

                    the same name in the script. Either way, you can't do that.

                    • 7. Re: Creating redaction button
                      xhawk Level 1

                      Right, but I don' declare the AddMyRedacts function until that line where the error is. The only other time AddMyRedacts is mentioned to that point is around line 8 under the addToolButton. I also don't have any other copies of the script in the folder. So I am not sure where this error is coming from. Am I missing something here?

                      • 8. Re: Creating redaction button
                        try67 MVP & Adobe Community Professional

                        Probably... This error means there's already a function (or maybe a

                        variable) with that exact name when the script arrives to that line.

                        • 9. Re: Creating redaction button
                          gkaiseril MVP & Adobe Community Professional

                          I am not aware of a property or method "app.doc"

                           

                          For enabling a button I would use:

                           

                          cEnable: "event.rc = (event.target != null);",

                           

                          I would define my function before having any script that calls or references that funciton.

                           

                          You can use the "typeof" method to see if a user written function exist.

                           

                          typeof  cFunctionName

                           

                          Returns "function" if your function has been installed and is available.

                           

                          You might want to look at

                           

                          Automating Redaction with Acrobat JavaScript by Thom Parker

                           

                          http://acrobatusers.com/tutorials/auto_redaction_with_javascript

                           

                          If you are using Acrobat X, update 10.1.1 changed the location of the previlaged script location.

                           

                          User JavaScript Changes for 10.1.1 (Acrobat | Reader)

                           

                          http://kb2.adobe.com/cps/915/cpsid_91534.html

                           

                          You should be updating the folder level scripts with Acrobat closed or you will need to close Acrobat before your folder level functions will become active.

                          • 10. Re: Creating redaction button
                            try67 MVP & Adobe Community Professional

                            app.doc is an undocumented property that returns the currently active

                            document. As such, it shouldn't be used...

                            • 11. Re: Creating redaction button
                              xhawk Level 1

                              I defined the function properly in another file. So all of that part of the code is now out. I can get the redaction to work from the console, but when I try to use the same code with the button I get this error:

                               

                              RedactionApp is not defined

                              4:Folder-Level:App:RedactionApp.js

                               

                              If I add the app.trustedFunction(RedactionApp), I get this error:

                               

                              this.applyRedactions is not a function

                              34:Folder-Level:App:RedactionApp.js

                              RedactionApp is not defined

                              1:App:Exec

                              • 12. Re: Creating redaction button
                                try67 MVP & Adobe Community Professional

                                Post your entire code at the moment.

                                • 13. Re: Creating redaction button
                                  xhawk Level 1

                                  Also I am using Acrobat 9. So it shouldn't be an issue with the correct folder.

                                  • 14. Re: Creating redaction button
                                    xhawk Level 1

                                    // if the application is Adobe Acrobat...then create the redaction button

                                        if(app.viewerType == "Exchange-Pro") {

                                     

                                    app.trustedFunction(RedactionApp);

                                     

                                    app.addToolButton({

                                                cName: "RedactionApp",

                                                cExec: "RedactionApp()",

                                                cTooltext: "Redact",

                                                cLabel: "Redact",

                                                cEnable: "event.rc = (app.doc != null)" });

                                    }

                                     

                                    // Quads for the different Redaction areas

                                     

                                    // Template 1 Quads

                                    var qdPage1Box1 =  [[50.84193420410156, 632.2653198242188, 322.8841857910156, 632.2653198242188, 50.84193420410156, 469.1158142089844, 322.8841857910156, 469.1158142089844]];

                                    var qdPage1Box2 = [[49.70368957519531, 440.6595764160156, 321.7459411621094, 440.6595764160156, 49.70368957519531, 277.51007080078125, 321.7459411621094, 277.51007080078125]];

                                    var qdPage1Box3 = [[50.083099365234375, 249.81263732910156, 322.1253356933594, 249.81263732910156, 50.083099365234375, 86.66313171386719, 322.1253356933594, 86.66313171386719]];

                                    var qdPage1Box4 = [[328.954833984375, 593.5648193359375, 592.64990234375, 593.5648193359375, 328.954833984375, 503.2633972167969, 592.64990234375, 503.2633972167969]];

                                    var qdPage1Box5 = [[329.7136535644531, 402.3385009765625, 593.40869140625, 402.3385009765625, 329.7136535644531, 312.0370788574219, 593.40869140625, 312.0370788574219]];

                                    var qdPage1Box6 = [[328.19598388671875, 211.49156188964844, 591.8909912109375, 211.49156188964844, 328.19598388671875, 121.19013977050781, 591.8909912109375, 121.19013977050781]];

                                     

                                    var quadList = [[qdPage1Box1, qdPage1Box2, qdPage1Box3, qdPage1Box4, qdPage1Box5, qdPage1Box6]];

                                     

                                    ////////////

                                    // Applying the redactions

                                     

                                    AddMyRedacts([qdPage1Box1, qdPage1Box2, qdPage1Box3,

                                                  qdPage1Box4, qdPage1Box5, qdPage1Box6]

                                                );

                                    this.applyRedactions({ bKeepMarks: false,

                                                           bShowConfirmation: true,

                                                           cProgText: "Itís going away"

                                                         });

                                     

                                    And the AddMyRedacts is

                                    function AddMyRedacts(quadList){

                                     

                                    {

                                      for(var pg=0; pg<this.numPages; pg++)

                                      {

                                        for(var i=0; i<quadList.length; i++)

                                        {

                                          this.addAnnot({type:"Redact", page:0, quads:quadList[i],

                                                         overlayText: " ",

                                                         alignment: 1, // center alignment

                                                         repeat:true

                                                        });

                                        }

                                      }

                                    }

                                    }

                                    • 15. Re: Creating redaction button
                                      try67 MVP & Adobe Community Professional

                                      You can't call this function from the folder-level script itself. You have

                                      to call it from somewhere else, after the file is already open, like from

                                      the tool button you've created.

                                      • 16. Re: Creating redaction button
                                        xhawk Level 1

                                        What function are you referring to? The AddMyRedacts function? It is its own .js file. Or are referring to the applyRedactions function? If so, I don't follow.

                                        • 17. Re: Creating redaction button
                                          try67 MVP & Adobe Community Professional

                                          I'm referring to this part:

                                           

                                          AddMyRedacts([qdPage1Box1, qdPage1Box2, qdPage1Box3,

                                           

                                                        qdPage1Box4, qdPage1Box5, qdPage1Box6]

                                           

                                                      );

                                           

                                          this.applyRedactions();

                                          This can't be outside of a function if it's in a folder-level script.

                                          • 18. Re: Creating redaction button
                                            xhawk Level 1

                                            So should I just use this?

                                             

                                            applyRedactions({ bKeepMarks: false,

                                                                   bShowConfirmation: true,

                                                                   cProgText: "Itís going away"

                                                                 });

                                             

                                            Or would it better to create a new function?

                                            • 19. Re: Creating redaction button
                                              try67 MVP & Adobe Community Professional

                                              At the folder level you should only define functions and declare variables.

                                              You can't actually call any methods because when this code executes no PDF

                                              file is open. It executes the moment the application opens.

                                              The functions that you define in the folder-level script can be called

                                              later on, from a button or from a document, when a document is open and

                                              available to use.

                                              • 20. Re: Creating redaction button
                                                Bernd Alheit Adobe Community Professional & MVP

                                                Where did you define the function RedactionApp?

                                                • 21. Re: Creating redaction button
                                                  xhawk Level 1

                                                  I defined it in the .js file. I have been trying to build this using this as reference: http://blogs.adobe.com/acdc/2011/03/silent-print-in-acrobat-using-javascript.html

                                                   

                                                  In that example the customSilentPrint is defined in the file. So I still don't understand what is wrong with mine.

                                                  • 22. Re: Creating redaction button
                                                    gkaiseril MVP & Adobe Community Professional

                                                    You can not use the "this" object in a folde script, you should be passing the object or processing as a parameter to the funciton or omit it altogether.

                                                     

                                                    From one of the articles I referenced in my earlier post:

                                                     

                                                    Automation alternatives

                                                    The same code presented here could be used verbatim in a Batch Script.

                                                     

                                                    A more interesting and useful way to run an automation script is with an Acrobat toolbar button or menu item. However, using one of these options requires that the code be enclosed in a trusted function.

                                                     

                                                    Code for creating toolbar buttons and trusted functions can be found in this article, Applying PDF security with Acrobat JavaScript.

                                                     

                                                    I see that the blog post you referenced also uses the trusted funciton for the silent print.

                                                    • 23. Re: Creating redaction button
                                                      Bernd Alheit Adobe Community Professional & MVP

                                                      You may publish the .js file on Acrobat.com and post the link here.