9 Replies Latest reply on May 25, 2015 10:44 AM by Flonas

    Redaction Javascript for batch or single use

    Flonas Level 1

      I regularly need to redact certain documents from 2 different sources. For each source, the areas for redaction are the same. One source has 2 areas that need redaction and the other source has 4 areas that need to be redacted on each page, anywhere from 9-10 pages per document. What I am trying to do is automate this process as it takes a lot of time to do this manually all the time. I am familiar with creating actions in Adobe so my thought is to create an action that can be applied to batches of documents from each source. Currently the action deletes a page (also part of the process) then I have "execute a javascript” then remove hidden information. The part I need help with is the "execute a javascript" part.

       

      I have looked around some and found that a drawing markup tool rectangle has default coordinates or rotated coordinates. I do not need to have anything to do with the rotated coordinate conversions. In order to find the default X/Y coordinates of the four corners of a drawing markup rectangle I can use this script successfully:

       

      "this.getAnnots()[0].rect


      this allows me to draw a box around the areas that I want redacted and then  get the X/Y coordinates to use in the javascript to tell it which areas I want redacted. Essentially I am looking for a javascript that will allow me to define a set of coordinates for the areas I want to redact(they will always be the same and I will get them using the above script unless otherwise directed) , mark them for redaction and apply the redactions. If the coordinates provided by the above script will work great. If I need to find the quad coordinates i will need separate script or instruction on how to find the quad coordinates for the areas I want redacted. Please help! I am using a rMBP that is about 2 months old and Adobe Acrobat X Pro

        • 1. Re: Redaction Javascript for batch or single use
          gkaiseril MVP & Adobe Community Professional

          You have a lot more work to do.

           

          Automating Redaction with Acrobat JavaScript by Thom Parker

          • 2. Re: Redaction Javascript for batch or single use
            Flonas Level 1

            I actually read this initially. The quad reference lookup part did not seem to work properly, perhaps because it was written for AAP 9.0 7 years ago and I am using AAP X? Specifically this piece seems to be an issue:

             

            "var rct = getAnnots(this.pageNum)[0].rect;”

             

            Perhaps because the rectangle tool is no longer part of the annotation tool set, it is now part of the drawing markup tool set and I do not know how to adjust the reference or if it would even work.

             

            Thoughts?

             

             

            Tom

            • 3. Re: Redaction Javascript for batch or single use
              gkaiseril MVP & Adobe Community Professional

              There are changes with every update to all products.

               

              I wrote a function to perform a reaction using that article with Acrobat 9 and have used it with both Acrobat 9 and XI without additional changes.

               

              If you carefully read the article and the following comments, you should find a correction to the code.

               

              Running the code for the first example  I get the following result:

               

               

              var rct = getAnnots(this.pageNum)[0].rect;
              var left = rct[0];
              var right = rct[2];
              var top = rct[3];
              var bot = rct[1];
              qd = [ [left, top, right, top, left, bot, right, bot] ] qd.toSource();

               

              SyntaxError: missing ; before statement
              6:Console:Exec
              undefined

               

              So I see the error is in line 6

               

              qd = [ [left, top, right, top, left, bot, right, bot] ] qd.toSource();

               

              That line should be 2 lines , or a semicolon needs to inserted after "bot]]; qd.toSource();

               

              So running the following code:

               

              var rct = getAnnots(this.pageNum)[0].rect;
              var left = rct[0];
              var right = rct[2];
              var top = rct[3];
              var bot = rct[1];
              qd = [ [left, top, right, top, left, bot, right, bot] ]; qd.toSource();

               

              Provides the following result:


              [[472.81201171875, 661.822021484375, 580.81201171875, 661.822021484375, 472.81201171875, 643.4219970703125, 580.81201171875, 643.4219970703125]]

              • 4. Re: Redaction Javascript for batch or single use
                Flonas Level 1

                Great! Thanks

                 

                Tom

                • 5. Re: Redaction Javascript for batch or single use
                  Flonas Level 1

                  Ok,

                  So far so good, that helped quite a bit and I was able to get the quads for the 2 areas I would like to redact. Now when I compile the code from the bottom of the article and follow the instructions:

                   

                  “To use this code, copy it to the Acrobat JavaScript Console <https://acrobatusers.com/tutorials/2006/javascript_console/>. Select and run Parts #1 and #2. Then select the code for the scheme that will be used on the current document and run it. Run only one scheme on one document.”

                   

                  I am not able to get past selecting and running parts #1 and #2.  Below is my code and the resulting error, I do not really know how to troubleshoot this code to tell what is missing from line 5. I believe it is because the quadList being referred to is not defined as such anywhere?

                   

                   

                  // Part 1: Quads for the different Redaction areas

                  var qdTitle = [[26.8800048828125, 779.9100341796875, 552.3200073242188, 779.9100341796875, 26.8800048828125, 693.510009765625, 552.3200073242188, 693.510009765625]];

                  var qdRFL = [[26.8800048828125, 693.510009765625, 87.04000854492188, 693.510009765625, 26.8800048828125, 656.3900146484375, 87.04000854492188, 656.3900146484375]];

                  //Part 2: Function for adding Redact Annotations to a PDF function

                  AddMyRedacts(quadList)  {

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

                  {

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

                                 this.addAnnot({

                                      type:"Redact", page:pg,

                                      quads:quadList[index]

                                 });

                            }

                       }

                  }

                   

                   

                  SyntaxError: missing ; before statement

                  5:Console:Exec

                  undefined

                   

                  Please help

                   

                  Thanks

                   

                  Tom

                  • 6. Re: Redaction Javascript for batch or single use
                    urielk13361039 Level 1

                    Hi Tom,

                    I believe the problem is that AddMyRedacts is not defined properly. Add the word function before it and that should fix it.

                     

                    It should look like this:

                     

                    // Part 1: Quads for the different Redaction areas

                    var qdTitle = [[26.8800048828125, 779.9100341796875, 552.3200073242188, 779.9100341796875, 26.8800048828125, 693.510009765625, 552.3200073242188, 693.510009765625]];

                    var qdRFL = [[26.8800048828125, 693.510009765625, 87.04000854492188, 693.510009765625, 26.8800048828125, 656.3900146484375, 87.04000854492188, 656.3900146484375]];

                    //Part 2: Function for adding Redact Annotations to a PDF

                    function AddMyRedacts(quadList)  {

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

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

                                   this.addAnnot({

                                        type:"Redact", page:pg,

                                        quads:quadList[index]

                                   });

                              }

                         }

                    }

                    // Part3: Applying the redactions

                    AddMyRedacts([qdTitle, qdRFL]);

                    this.applyRedactions({bKeepMarks: false, bShowConfirmation: true, cProgText: "It's going away" });

                     

                    P.S: To run this code put it in the console, select it all with ctrl+a, and then press ctrl+enter.

                    • 7. Re: Redaction Javascript for batch or single use
                      Flonas Level 1

                      Urielk,

                      This was outstanding, thank you for the help, this is now running successfully, however I have one issue. I only want this script to run and apply to one page of a certain document that I get regularly and the page I got the script from says:

                       

                      "This code walks through the document pages and adds Redact Annotations. One annotation is added for each quad in the list. The first page of the file is a title page, so it’s not included in the redaction.”


                       

                      How do I adjust the Part 2 script so that it only applies to the first page instead of vice versa?

                       


                      • 8. Re: Redaction Javascript for batch or single use
                        try67 MVP & Adobe Community Professional

                        Remove the first for-loop and change this parameter:

                        page:pg

                        To:

                        page:0

                        • 9. Re: Redaction Javascript for batch or single use
                          Flonas Level 1

                          Try67,

                          this worked fantastically. I have been able to successfully compile an action in Acrobat that full process documents of like kind either singly or by the folder. Thank you so much.

                           

                          Tom