11 Replies Latest reply on Feb 10, 2016 12:06 PM by Christianhchuk

    Acrobat Pro XI Java: Deleting Page is Very Slow

    Christianhchuk Level 1

      Hi Everyone,

       

      Below is a set of code I got working in Acrobat XI to pull up a popup window that, when the user selects yes, is able to search for a hidden keyword on certain pages in the PDF and then delete the corresponding pages.  This works, but the problem is that it takes almost a minute to process.  I would love someone's input as to what might be slowing the process down.  I am very new to Java so any specific suggestions would be greatly appreciated!

       

      Thank you in advance,

      Christian

       

      var cMsg = "Continuing with the current action will remove the CHES application and its data.  This operation may take a minute to complete.";

      cMsg += "\n\nDo you want to continue?";

      var nRtn = app.alert(cMsg,2,2,"Question Alert Box");

      if(nRtn == 4)

      {// A yes Response

        // Code for doing the thing you do on a yes

        console.println("The Response Was Yes");

      for (var p=this.numPages-1; p>=0; p--) {

          for (var n=0; n<this.getPageNumWords(p); n++) {

             if (this.getPageNthWord(p, n) == "CHESDELETE") {

              this.deletePages(p);

              break;

      }

      }

      }

      }

       

      else if(nRtn == 3)

      {//No Response

      console.println("The Response Was No");

      }

       

      else  

      { //Unknown Response

        console.println("The Response Was somthing other than Yes/No: " + nRtn);

      }

        • 1. Re: Acrobat Pro XI Java: Deleting Page is Very Slow
          try67 MVP & Adobe Community Professional

          Searching an entire document is a lengthy process, especially if there are a lot of pages and a lot of words on each page.

          I don't really see how your code can be improved.

          • 2. Re: Acrobat Pro XI Java: Deleting Page is Very Slow
            Christianhchuk Level 1

            Thanks for the fast reply!  Is there anyway to use Indexing to speed this up do you think?  I have also been looking for a way to search for an image element in the doc instead of searching for nth word.  I have been totally unable to find any examples of this in any forums, however.

            • 3. Re: Acrobat Pro XI Java: Deleting Page is Very Slow
              try67 MVP & Adobe Community Professional

              No, neither option is possible with a script.

               

              On Mon, Dec 14, 2015 at 10:20 PM, Christianhchuk <forums_noreply@adobe.com>

              • 4. Re: Acrobat Pro XI Java: Deleting Page is Very Slow
                Test Screen Name Most Valuable Participant

                Simple test: take out the page delete and see if it speeds up. The chances are it's the text extract.

                • 5. Re: Acrobat Pro XI Java: Deleting Page is Very Slow
                  Christianhchuk Level 1

                  Thank you everyone!  I guess I will just keep the "This may take a minute" language.  If any other thoughts come up feel free to reply - I will be active on the forum ;D

                  • 6. Re: Acrobat Pro XI Java: Deleting Page is Very Slow
                    try67 MVP & Adobe Community Professional

                    There is possibly a more efficient way of doing it, but it requires using an Action, and a script.

                    You can use the Search & Remove Text command to place redaction annotations over the terms you're looking for, and then use another script to remove the pages where those redactions are located. It might work faster then searching the file yourself...

                    • 7. Re: Acrobat Pro XI Java: Deleting Page is Very Slow
                      Christianhchuk Level 1

                      I will try this!!!  Thank you very much - I will probably mark this as correct, but I just want to do it first to make sure this technique functions well.

                      • 8. Re: Acrobat Pro XI Java: Deleting Page is Very Slow
                        Christianhchuk Level 1

                        Hi again,  I am having trouble finding a way to start the action via Java.  It looks like I cannot trigger the "Execute a menu item" action for anything other than what is prepopulated by Adobe.  So this leaves me with coding for the action to start using Java, but I cannot find anywhere a way to simply start the action sequence.  Am I missing something super basic?  This is where the action is located - I feel like I am so close!  Again, your help so far has been awesome.  Any help is greatly appreciated.

                        • 9. Re: Acrobat Pro XI Java: Deleting Page is Very Slow
                          Christianhchuk Level 1

                          Actually, after searching in this forum I JUST saw a post from you stating that it is not possible.  I apologize for the redundancy!

                          • 10. Re: Acrobat Pro XI Java: Deleting Page is Very Slow
                            Test Screen Name Most Valuable Participant

                            A tip if you're searching for info: Java isn't short for JavaScript, it's an entirely different thing. So if you search just for Java, or even for Java Script (no space), you may get info that isn't suitable for your needs. Hope this helps you in future.

                            • 11. Re: Acrobat Pro XI Java: Deleting Page is Very Slow
                              Christianhchuk Level 1

                              Hi Everyone,

                               

                              After revisiting this topic, I realized a solution.  So hopefully anyone in my situation can benefit in the future!

                               

                              **As a brief recap, I had an interactive PDF application where multiple pages are "Spawned" when certain options (checkboxes) are selected.  When items were deselected, I needed a way to get those pages out of the document.  The search for Nth word approach worked, but became very slow, especially as the PDF grew larger.  The approach below will allow you to delete spawned pages very quickly from a document based on a button/field value, and can be adjusted accordingly.

                               

                              Steps:

                              1. Somewhere in the document (not on the template, unless you make sure field names are static when spawned) create a Text Field, and format it to hold numbers with zero decimals.  This is your Variable Container (So, for instance, I named it CHES Container).
                              2. Next, go to the template that needs to be spawned at a later time. In the page icons toolbar right click on your template page, and go to Properties>Actions
                              3. For Select Trigger choose "Page Open" ; For Select Action choose "Run a Java Script"
                              4. Paste and Modify the following script:

                              -----------------------------------------

                              var p = this.pageNum;

                              console.println(p);

                               

                              this.getField("CHES Container").value=p;

                              -----------------------------------------

                                   5.  This action will tell your template page, when spawned, to identify its own page number, and place it in the "Variable Container", which again, for me is called "CHES Container".

                                        NOTE: Test to make sure your container is showing a number, and that it is accurate.  Later you can hide this field, but for now it is useful for finding any errors that may arise.

                                   6. Click OK and go to the button (checkbox etc.) that will trigger the deletion of these specific pages.

                                   7. Go to field Properties> Actions.  For Select Trigger choose "Mouse Up" ; For Select Action choose "Run a Java Script"

                                   8. Paste and modify the following script:

                              -----------------------------------------

                              var p = this.getField("CHES Container").value;

                              this.deletePages({nStart: p, nEnd: p+2});

                              -----------------------------------------

                              NOTE: nEnd: p+2 is simply adding 2 pages to the start range.  So just modify accordingly to suit the number of spawned pages there are that need deleting.

                               

                              Just as an FYI, my complete trigger Checkbox script was:

                              -----------------------------------------

                              var CHES = this.getField("CHES Check");

                              var CHES1 = this.getTemplate("CHES Pg1");

                              var CHES2 = this.getTemplate("CHES Pg2");

                              var CHES3 = this.getTemplate("CHES Pg3");

                              var p = this.getField("CHES Container").value;

                               

                              if(CHES.value=="Yes")

                              {

                              CHES1.spawn();

                              CHES2.spawn();

                              CHES3.spawn();

                              }

                              else

                              {

                              this.deletePages({nStart: p, nEnd: p+2});

                              }

                              -----------------------------------------

                               

                              Please let me know if I missed anything or if you have questions!  Thank you again to everyone for your input and patience.