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.
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
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.
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.
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);
fr.left = 67;
fr.top = 671;
fr.right = 149;
fr.bottom = 621;
annot2 = PDPageCreateAnnot(pdPage, ASAtomFromString("Link"),&fr);
PDPageAddAnnot(pdPage, -2, annot2);
Is it the correct way,or I am doing something wrong??
Thanks a lot..
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.