9 Replies Latest reply on May 9, 2016 6:00 AM by alexh90310518

    conditional page delete.

    tpjmlu26

      ( I am using Adobe Pro XI and Adobe Standard XI)

      I am looking for a Acroform button script to delete page 2 but only if the PDF is 3 pages ( or greater than 2 pages.)

       

      My form is 2 pages by default and if the user needs to expand the document they can click a check box to spawn a new Template that becomes the new page 2. I have a reset button that will reset the form fields and deletes the new page 2.

       

      THE PROBLEM: if the user does not opt to generate a new page 2 leaving it as a 2 page document as soon as they hit reset button the document now becomes a 1 page document.

       

      So I need to figure out a way to use the page count feature to evaluate the PDF to see if it greater then 2 pages and if so then run the delete page 2 script.

       

      The user will be using Adobe Reader XI or Reader DC to fill out the form.

       

      Any help will be greatly appreciated from this scripting newbie.

       

      Examples would help me modify to match my text fields.

       

      Thanks in advance for your Help!

      Tom McCarty

        • 1. Re: conditional page delete.
          gkaiseril MVP & Adobe Community Professional

          I would look at providing a document level control field that counts how many times the new page 2 has been spawned or deleted. If the count is one hide the spawn button and if 0 show the spawn field.

          • 2. Re: conditional page delete.
            tpjmlu26 Level 1

            gkaiseril,

            I am already hiding the spawn button if it is used once. Actually, I am using a blank text field to cover the spawn check box using show / hide.

             

            My  need is to come up with a way to NOT delete page 2 when the reset button is selected AND  the spawn button was not pushed. The Form  is normally a 2 page document and it only becomes a 3 page document if the spawn button is pushed.

             

            this.resetForm(["PO"]);

            var g = this.getField("Current P.O. #");
            g.value = Math.round(g.value + 1);

             

            this.deletePages(1);  //this is the problem code...I need to change it to evaluate or some method to determine is the PDF is 3 pages if it is 3 pages then run the delete script if not then null.

            I am not very good with scripting so this has been a road block for me.

             

            I hope I was able to explain my problem a little better.

            Thanks for the input all input is welcome and considered

            • 3. Re: conditional page delete.
              tpjmlu26 Level 1

              var spwndel = this.numPages.value;

              if(spwndel>1) this.deletePages(1);

               

              This the code I am trying to use to make this happen but it not working and not causing errors.

               

              This would be easier if Adobe had scripting help pop ups like Excel VBA does

              • 4. Re: conditional page delete.
                George_Johnson MVP & Adobe Community Professional

                Change it to:

                 

                var spwndel = this.numPages;

                 

                Or simply:

                 

                if (numPages > 1) {

                    deletePages(1);

                }

                • 5. Re: conditional page delete.
                  tpjmlu26 Level 1

                  Thanks George!!! Looks like I forgot the brackets. I tried with and without the .value

                   

                   

                   

                  Not very sure of the syntax yet.

                  I am looking to find a Good resource book for Adobe JavaScript.

                  I am using the JavaScript reference that you can find on-line but that has only taken me so far.

                   

                  simple stuff like the meaning of "++", or " &&" hard to find those resources answers

                  • 6. Re: conditional page delete.
                    gkaiseril MVP & Adobe Community Professional

                    Adobe has the Acrobat Developer Center that has links to Acrobat development documentation.

                     

                    Mozilla Developer Network has a number of documents abut JavaScript.

                     

                    There are also several books about creating Acrobat forms and JavaScript.

                     

                    Using the Acrobat JavaScript API Reference one would see that the page number in Acrobat JavaScript is 0, zero, based. So the first page is page number 0 in JavaScript.

                    • 7. Re: conditional page delete.
                      alexh90310518 Level 1

                      If you're still looking for resources to help with learning JavaScript syntax and language I recommend w3schools, they have a very well explained set of tutorials ranging through the vast majority of JavaScript going from basics to more advanced techniques, I learned a lot of what I know (Still very little) from there and still reference back to it now and again. YouTube is also a great resource for just general browsing though it's more difficult to find something specific which is where these good folk come into their stride.

                      • 8. Re: conditional page delete.
                        Karl Heinz Kremer Adobe Community Professional

                        Just keep in mind that w3schools is heavily focused on JavaScript for the Web. Any JavaScript implementation has two parts: The JavaScript "core" language, and the application specific extensions to that core language. The first part is the same for all implementations (that is ignoring any version specific differences), the second part is completely different: When you write JavaScript for the web, it will run in most instances in the browser, so you have functionality to manipulate browser windows and communicate with the web server. You don't have that in Acrobat. In Acrobat's implementation, this additional functionality is about PDF documents, annotations, form fields, and other things that are specific to Acrobat and PDF.

                         

                        So, when you learn JavaScript, you have to find that line that separates the core language from the extensions. For information about Acrobat's specific JavaScript functionality, take a look at the API documentation: Acrobat DC SDK Documentation

                        • 9. Re: conditional page delete.
                          alexh90310518 Level 1

                          I was mostly referring to their explanations of things like functions, loops, operators, expressions and variables. I found that a lot of their stuff was irrelevant for Acrobat it's true but for understanding basics such as "| |" "&&" "++" meanings it was a very helpful resource.

                           

                          I agree with you fully the API reference is great for Acrobat but I found it's layout to be far too extensive when searching for something specific, especially being a beginner at both Acrobat and JavaScript using the API was almost akin to finding needles in very large confusing haystacks and more often than not I got frustrated and gave up.

                          w3Schools and places like that just gave me a place to quickly find my feet in JavaScript by explaining the very basics even though I admit I have much much more to learn.