4 Replies Latest reply: Aug 30, 2012 12:07 PM by Mayerchak RSS

    How to set Layer Visibility on Initial View?

    Mayerchak Community Member

      I have created some forms that have multiple layers in them. They are several pages long. On page 1 there are 3 radio buttons . . . the user selects their appropriate user type and that turns on the correct layer and turns off the other layers. Unfortunately, if they go to page 2 before clicking one of the butttons, they see all of the layers at once, and it's a jumbled mess.

       

      Is there a way to set the default layer visibility so that when you open the PDF, it shows only the layer I want it to? I can't find this in the initial view settings.

       

      Thanks in advance for any help provided!

        • 1. Re: How to set Layer Visibility on Initial View?
          GKaiseril ACP/MVPs

          Yes, you can use a document level script to set the state of the OCG, Optonal Content Group or layer, objects intial states.

           

          var nOCG = 0; // number of OCG to display

          // set all OCGs off

          var ocgs = this.getOCGs();

          ocgs[0].initState.constants.states.off;

          // turnon the one OCG for initial view

          ocgs[nOCG].initState.constants.states.on;

          • 2. Re: How to set Layer Visibility on Initial View?
            Mayerchak Community Member

            Thanks! I'll give that a try.

             

            p.s. what's a good source of documentation on javascript as it relates to Acrobat? I.e. what you can do in Acrobat via javascript. Is there a book or online resource you know of?

            • 4. Re: How to set Layer Visibility on Initial View?
              Mayerchak Community Member

              Hi,

               

              I'm finally getting around to using the script you so generously provided. Client sat on the project for months, and now they want it fixed.

               

              I have 4 layers, or OCGs (sounds like that is what javascript calls them), named "Common", "Staff", "Supervisor", and "Manager" - and I would like the intial view to show the layers "Common" and "Staff" . . . how would I plug that into the script above?

               

              Does javascript refer to the OCGs by name, or do they have numbers associated with them?

               

              Here is my attempt - but really just a guess, and it did not work:

               

              function InitialLayerView()

              {

              var nOCG = 1;  // number of OCG to display

              var nOCG2 = 2;  // number of OCG to display

              // set all OCGs off

              var ocgs = this.getOCGs();

              ocgs[0].initState.constants.states.off;

              // turnon the two OCGs for initial view

              ocgs[nOCG].initState.constants.states.on;

              ocgs[nOCG2].initState.constants.states.on;

              }

               

              Also - once I close the script, save and reopen the file, should I have to do anything to run the script? I'm hoping it just runs on open.

               

              Thanks for any help you can give!