6 Replies Latest reply on Dec 26, 2011 10:34 PM by maxwyss

    Unable to get deletePages to function in Adobe Reader

    Walker.Cj3

      Good Evening,

       

      I've been writing a JS to delete certain pages of a document depending on the value selected by the end user.  While viewing it in Adobe Acrobat Pro 9 for MAC the function works fine.  But when viewing it in Adobe Reader 10.0.1 for MAC and Adobe Reader X Ver 10.1.1 for Windows, the this.deletePages function does not seam to function.

       

      I've tried the document with and without Enabled Usage Rights.

       

      I have not tired this document on older versions of Adobe Reader to date.

       

      var item = getField("TS.RelItem").value;

       

      if (item == "3(B)")

      {

          // A MouseUp action

          var nButton = app.alert({

              cMsg: "You selected Release Item QR&O 15.01,3(b). \n\n Is this the CORRECT Release Item?  \n\n\nThis will remove all documents that do not pertain to a 3(b) release" ,

              cTitle: "Confirm Release Item",

              nIcon: 2, nType: 2

                 

          });

          if ( nButton == 4 )

      {

      // 3(B)

      this.deletePages({nStart: 7, nEnd: 15});

      getField("Confirm").checkThisBox(0,true);

      }

      else if ( nButton == 3 )

      {

      getField("Confirm").checkThisBox(0,false);

      }}

       

      else if (item == "4(A)")

      {

          // A MouseUp action

          var nButton = app.alert({

              cMsg: "You selected Release Item QR&O 15.01,4(a). \n\n Is this the CORRECT Release Item?  \n\n\nThis will remove all documents that do not pertain to a 4(a) release" ,

              cTitle: "Confirm Release Item",

              nIcon: 2, nType: 2

                 

          });

          if ( nButton == 4 )

      {

      // 4(A)

      this.deletePages({nStart: 7, nEnd: 12});

      getField("Confirm").checkThisBox(0,true);

      }

      else if ( nButton == 3 )

      {

      getField("Confirm").checkThisBox(0,false);

      }}

       

       

       

      if (item == "4(B)")

      {

          // A MouseUp action

          var nButton = app.alert({

              cMsg: "You selected Release Item QR&O 15.01,4(b). \n\n Is this the CORRECT Release Item?  \n\n\nThis will remove all documents that do not pertain to a 4(b) release" ,

              cTitle: "Confirm Release Item",

              nIcon: 2, nType: 2

                 

          });

          if ( nButton == 4 )

      {

      // 4(B)

      this.deletePages({nStart: 7, nEnd: 12});

      getField("Confirm").checkThisBox(0,true);

      }

      else if ( nButton == 3 )

      {

      getField("Confirm").checkThisBox(0,false);

      }}

       

       

      else if (item == "4(C)")

      {

          // A MouseUp action

          var nButton = app.alert({

              cMsg: "You selected Release Item QR&O 15.01,4(c). \n\n Is this the CORRECT Release Item?  \n\n\nThis will remove all documents that do not pertain to a 4(c) release" ,

              cTitle: "Confirm Release Item",

              nIcon: 2, nType: 2

                 

          });

          if ( nButton == 4 )

      {

      // 4(C)

      this.deletePages({nStart: 7, nEnd: 12});

      getField("Confirm").checkThisBox(0,true);

      }

      else if ( nButton == 3 )

      {

      getField("Confirm").checkThisBox(0,false);

      }}

       

      else if (item == "5(A)")

      {

          // A MouseUp action

          var nButton = app.alert({

              cMsg: "You selected Release Item QR&O 15.01,5(a). \n\n Is this the CORRECT Release Item?  \n\n\nThis will remove all documents that do not pertain to a 5(a) release" ,

              cTitle: "Confirm Release Item",

              nIcon: 2, nType: 2

                 

          });

          if ( nButton == 4 )

      {

      // 5(A)

      this.deletePages({nStart: 11, nEnd: 14});

      this.deletePages({nStart: 7, nEnd: 8});

      getField("Confirm").checkThisBox(0,true);

      }

      else if ( nButton == 3 )

      {

      getField("Confirm").checkThisBox(0,false);

      }}

       

      else if (item == "5(C)")

      {

          // A MouseUp action

          var nButton = app.alert({

              cMsg: "You selected Release Item QR&O 15.01,5(c). \n\n Is this the CORRECT Release Item?  \n\n\nThis will remove all documents that do not pertain to a 5(c) release" ,

              cTitle: "Confirm Release Item",

              nIcon: 2, nType: 2

                 

          });

          if ( nButton == 4 )

      {

      // 5(C)

      this.deletePages({nStart: 11, nEnd: 14});

      this.deletePages({nStart: 7, nEnd: 8});

      getField("Confirm").checkThisBox(0,true);

      }

      else if ( nButton == 3 )

      {

      getField("Confirm").checkThisBox(0,false);

      }}

       

      else if (item == "5(D)")

      {

          // A MouseUp action

          var nButton = app.alert({

              cMsg: "You selected Release Item QR&O 15.01,5(d). \n\n Is this the CORRECT Release Item?  \n\n\nThis will remove all documents that do not pertain to a 5(d) release" ,

              cTitle: "Confirm Release Item",

              nIcon: 2, nType: 2

                 

          });

          if ( nButton == 4 )

      {

      // 5(D)

      this.deletePages({nStart: 13, nEnd: 15});

      this.deletePages({nStart: 9, nEnd: 10});

      getField("Confirm").checkThisBox(0,true);

      }

      else if ( nButton == 3 )

      {

      getField("Confirm").checkThisBox(0,false);

      }}

       

      else if (item == "5(F)")

      {

          // A MouseUp action

          var nButton = app.alert({

              cMsg: "You selected Release Item QR&O 15.01,5(f). \n\n Is this the CORRECT Release Item?  \n\n\nThis will remove all documents that do not pertain to a 5(f) release" ,

              cTitle: "Confirm Release Item",

              nIcon: 2, nType: 2

                 

          });

          if ( nButton == 4 )

      {

      // 5(F)

      this.deletePages({nStart: 13, nEnd: 15});

      this.deletePages({nStart: 9, nEnd: 10});

      getField("Confirm").checkThisBox(0,true);

      }

      else if ( nButton == 3 )

      {

      getField("Confirm").checkThisBox(0,false);

      }}

       

      else if (item != "4(C)")

      {

      }

        • 1. Re: Unable to get deletePages to function in Adobe Reader
          Dave Merchant MVP & Adobe Community Professional

          From the JavaScript documentation in the Acrobat SDK:

           

          (Acrobat 6.0): Beginning with version 6.0, this method deletes spawned pages from within Adobe Reader for documents with forms usage rights enabled.

           

           

          See doc.spawnPageFromTemplate() for more information on what a spawned page is. You cannot delete normal pages in a Reader-Extended document as "changing the document" is one of the permissions which is blocked when you apply RE (which in turn you need in order for the function to exist in Reader at all).

          • 2. Re: Unable to get deletePages to function in Adobe Reader
            Walker.Cj3 Level 1

            Thank you Dave,

             

            I have been muddling over this for a month now.  I admit I am not experienced with Java as most, but I can't seem to find anything from the spawn template family that will help me out.

             

            In short, I have a 24 page document that I want to hide or remove pages according to a users response on the first page, or Generate a new document with the pages required for the end user.

             

            If you could provide me a short example of what I may need I would greatly appreciate it.

            • 3. Re: Unable to get deletePages to function in Adobe Reader
              Dave Merchant MVP & Adobe Community Professional

              As I said, you cannot remove or hide normal pages in Reader. Spawned pages are generated using special page templates in the file, and loading them in the first place is no longer possible in Adobe Reader with the extended rights matrix which Acrobat applies. Templates were an earlier method of doing what we now achieve using dynamic XFA forms, so their support is all-but-gone in the current versions. They were specifically designed to function as part of the forms system, not as a way to show and hide pages.

              • 4. Re: Unable to get deletePages to function in Adobe Reader
                maxwyss Level 4

                Acrobat's extended rights never included Templates (unless it was an oversight). Therefore, you always needed the expensive Reader Extensions Server for allowing Templates.

                 

                Themplates are available, and they are part of ISO 32000 (and therefore PDF). Templates are by far not "something of the past" which the above message makes believe. On the other hand, dynamic XFA forms are proprietary, and they are NOT a replacement of Templates; they are their own kind of thing. XFA is by far not a "newer" technology than PDF (well, actually, it is; it is about three years younger than PDF)

                 

                Now, for the Forms Manager to decide on the technology, it is important to be fully aware of the implications of the choice.

                 

                Now, for the actual problem, to customize documents, which may even be printed, one would have to look at the situation from a different angle. Depending on the workflow and the number of documents to be created, one might think of a server-side assembled document (that's for higher volumes). In this scenario, the item selection would be a front end, and then the customized document would be assembled on the server side, using appropriate tools.

                 

                On the other end of the scale, if provided as a "srevice", the request could be handled manually by an operator. In this case, the operator would need Acrobat Pro, and then, Templates are the way to go. Of course, this approach does not aloow "user self-service".

                 

                Another approach would be what I call "virtual pages". In this case, the document itself has a fixed number of pages (usually 1 or 2), and the contents is either dynamically generated, or by showing/hiding either fields or OCGs, together with a page navigation system. An example: on page 1 of your document, you have the overview over the contents, where you customize the document. On page 2, you have for each possible page an OCG defined. Navigation buttons are used to show/hide the according OCG, giving you the effect of switching from page to page. If the document has to be printed, you would provide a printing routine, which shows/hides the OCGs, prints the page, shows/hides the next OCG, prints the page, and so on. This can be done in Reader even without the need of any extended rights (unless you want to save the configuration of the customized document).

                 

                Also working with Reader and Acrobat's extended rights would be using Button fields, where the icon is the actual page. Again, a show/hide logic is used for the navigation. This would also allow for the scenario where the user customizes the document exactly one time, and when saving the customized document, the unused fields would be discarded. This may even mean that the fields used for the customization would be deleted as well (would be a good idea anyway, as the contents of the non-selected pages has been deleted.

                 

                The advantages of the two approaches above is that no pages are dynamically created, and therefore, we have the visual quality possible using PDF, which also means that printing will provide the expected results, over which we have full control.

                 

                Hope this can help.

                 

                Max Wyss.

                • 5. Re: Unable to get deletePages to function in Adobe Reader
                  Dave Merchant MVP & Adobe Community Professional

                  Support for templates (the proper title of which are "named pages") was more extensive in earlier versions of Adobe Reader, and has intentionally been depreciated so they are now no longer supported except as required to allow compliant rendering and workflows using dynamic stamps (which use the Template object as a back end). In Reader 5 to 6, named pages could be  created, hidden and deleted with extended forms rights (EFR) but this was removed in Reader 7. We still have Reader support for the template.spawn() method provided the document has EFR, but that's it. Working with named pages is in all practical senses now just an Acrobat feature, and  a vanishingly-rare one at that.


                  Named pages are indeed part of the ISO specification (12.7.6), but as an optional element - there is no requirement for a compliant renderer to do anything with them other than display the current set of previously-spawned pages (which Reader does), nor any reference to how they're created or loaded. All the JavaScript functions relating to the Template object are proprietary, and you can't use named pages without JavaScript enabled - you simply can't rely on the document working properly in a public deployment where users are likely to disable the JS engine or view PDFs with something other than Adobe Reader desktop.

                   

                  Within the feature set of Adobe Reader X, the core functions previously-provided by named pages (such as adding dynamic pages to a form) are now very firmly the domain of XFA and LiveCycle Designer. There is no need for EFR and pages can be added and removed very easily (they usually contain parts of a form but don't have to). Unlike with workarounds using OCGs or button images, the resulting files are accessible, have no legal issues with unredacted content, and will render and print with complete reliability in  compliant software - pages are actually added and removed from the tree, not just hidden, so in the case of a contract there's no chance another viewer could be shown a different page to the one the signer was shown.  Adobe is working hard to bring complete XFA support to mobile devices, but with the issues surrounding JavaScript on iOS unlikely to go away anytime soon, script-switched content (including the Template object) is getting more and more difficult to rely upon. It's a shame, but we have to put up with the politics.

                   

                  Acrobat's extended rights never included Templates (unless it was an oversight). Therefore, you always needed the expensive Reader Extensions Server for allowing Templates.

                   

                  Themplates are available, and they are part of ISO 32000 (and therefore PDF). Templates are by far not "something of the past" which the above message makes believe. On the other hand, dynamic XFA forms are proprietary, and they are NOT a replacement of Templates; they are their own kind of thing. XFA is by far not a "newer" technology than PDF (well, actually, it is; it is about three years younger than PDF)

                  • 6. Re: Unable to get deletePages to function in Adobe Reader
                    maxwyss Level 4

                    Agreed, in its very first incarnation of Extended Rights, tied to Reader 5, the showing/hiding of Template pages was possible, if I can remember correctly. Creating Templates is definitely not needed for run-time use of a document; deleting would be nice, in order to reduce the file size. But I must agree that not allowing the hidden property at all causes some issues requiring workarounds for me (weaken Reader by being forced to spawn and destroy pages). I guess there was a new prduct manager involved with Acrobat 6…

                     

                    Well, if Adobe tries to bring XFA support to mobile devices, that's fine, AS LONG AS THEY DON'T CALL THIS PDF. However, unless XFA files get on a serious diet, there will be issues against using them on mobile devices. It will take its very good time for the mobile operators to set up good LTE coverage all over the place… and in the meantime, we hang around with EDGE.

                     

                    Maybe I am stuck in my way of thinking, but how would you implement context-dependent optional elements without programming (and thus creating its own app)?