9 Replies Latest reply: Sep 6, 2012 5:01 AM by poortip87 RSS

    How to set action of a link to "Set Layer Visibility" via plugin?

    poortip87 Community Member

      Hi

       

      I have few shapes in a pdf document which are linked to some layers. I need to update the links according to the object data of a particular shape. I am able to get the object data but I am not able to set the link action. Please guide.

       

      Thanks..

        • 1. Re: How to set action of a link to "Set Layer Visibility" via plugin?
          lrosenth Adobe Employee

          What seems to be the problem?

           

          Create the action (PDAction) and assign it to the Link annot.

          • 2. Re: How to set action of a link to "Set Layer Visibility" via plugin?
            poortip87 Community Member

            It works fine for the links created by acrobat. But we have a pdf created by Visio 2010. Shapes are converted regardless of their protection or behavior. Shape custom properties can be converted to PDF object data. Now we need to create a link on the shape accroding to the object data for that shape. We are able to get the object data. But when we tried to create the link by setting link action it doesn't work for these shapes.

             

            Please guide..

             

            Thanks..

            • 3. Re: How to set action of a link to "Set Layer Visibility" via plugin?
              poortip87 Community Member

              Hi

               

              I am able to create link and set actions on that link. But i am not able to set "SetLayerVisibility" action. I have searched in the documentation but didn't got action key for this action.

               

              Please help..

              • 4. Re: How to set action of a link to "Set Layer Visibility" via plugin?
                Test Screen Name CommunityMVP

                You need to know that "layer" is just what the UI calls "optional content" (=optional content group, =OCG).

                 

                Now refer to 12.6.4.12 in the PDF specification.

                • 5. Re: How to set action of a link to "Set Layer Visibility" via plugin?
                  poortip87 Community Member

                  yes that I understand but what I want to do is ,we  want to create a link annot and set its action to "SetLayer Visibility". It can be done via  UI by using link tool and creating a link and setting its action to "SetLayerVisibility". It will be linked to the target layers as

                   

                  link.jpg

                  Can we do this via a plugin??

                  I know that we can create a link annot and set its action via plugin. I have already done that. I just need to know how to set its action like this.

                   

                  Thanks..

                  • 6. Re: How to set action of a link to "Set Layer Visibility" via plugin?
                    Test Screen Name CommunityMVP

                    If you can do something in the UI you can always do it in the plug-in API (with very few exceptions, e.g. Reader enabling which relies on proprietary techniques). Sometimes it is easy, sometimes not.

                     

                    The PDF Specification describes the format needed for the action object. Personally I would take that information, and make a Cos object, then use the Cos object as an action.

                    • 7. Re: How to set action of a link to "Set Layer Visibility" via plugin?
                      poortip87 Community Member

                      I tried that as well but it didn't worked..Here's how I tried

                       

                      ASText  OCGtitle =ASTextFromScriptText( "LayerA" ,kASRomanScript);

                                      PDOCG  ocg =  PDOCGCreate(pdDoc, OCGtitle);

                             // get the cos document

                                      CosDoc  cosDoc =  PDDocGetCosDoc(pdDoc);

                                      // we want a new action, one that sets the OCG state on

                                      PDAction  myAct1 =  PDActionNew(pdDoc,  ASAtomFromString( "SetOCGState" ));

                       

                                         // Create and populate the CosArray for the On Action

                                      CosObj  newOnArray =  CosNewArray(cosDoc,  false ,3);

                                      CosObj  onName =  CosNewNameFromString(cosDoc,  true ,  "ON" );

                                      CosArrayInsert(newOnArray, 0, onName);

                                      CosArrayInsert(newOnArray, 1,  PDOCGGetCosObj(ocg));

                                      CosArrayInsert(newOnArray, 2,  CosNewNull());

                       

                                        // Assign the newly created CosArrays to the Action's dictionary

                                      CosObj  onObj =  PDActionGetCosObj(myAct1);

                                         CosDictPutKeyString(onObj, "State"  ,newOnArray);

                       

                                      PDAnnot annot2;

                                      ASFixedRect fr;

                                      fr.left  = 67;

                                      fr.top  = 671;

                                      fr.right = 149;

                                      fr.bottom = 621;

                       

                                       annot2 = PDPageCreateAnnot(pdPage, ASAtomFromString("Link"),&fr);

                                       PDPageAddAnnot(pdPage, -2, annot2);

                                    

                                      PDLinkAnnotSetAction(annot2, myAct1);

                       

                      Is it the correct way,or I am doing something wrong??

                       

                      Thanks  a lot..

                       


                      • 8. Re: How to set action of a link to "Set Layer Visibility" via plugin?
                        Test Screen Name CommunityMVP

                        The principle looks good. Let's look at what gets created.

                         

                        onArray: [ /ON ocg null ]   -- why the null?

                        onObj: << /State onarray >>  -- I guess we probably inherit the necessary S entry

                         

                        I see that PDOCGCreate is supposed to create a new OCG entry. Is that right? And if so, where do you assign content to that group. PDOCGCreate does not seem to be for obtaining a PDOCG for an existing OCG, if that is what you wanted to do.