Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

Annotations linking to pages/images

Help
Paolo
2011-08-31
2013-05-28
  • Paolo
    Paolo
    2011-08-31

    Hi all,
    I'm pretty new to JPod and pdf rendering. I managed to create a pdf with multiple images, one per page. Now I would like to add invisible annotations over certain areas of the images that link to other pages inside the same document. Copying the code samples I created some annotations but I have no idea on how to add an action that goes to a given page number or to a given image (that is almost equivalent in my case)
    Thanks in advance for any help or link to documentation/examples.
    Ciao,
    Paolo

     
  • mtraut
    mtraut
    2011-09-06

    Hi, sorry for the delay..

    There's an example for adding a link "CreateLink". The only thing to do is use another action

            // create and add a link
            PDLinkAnnotation annot = (PDLinkAnnotation) PDLinkAnnotation.META.createNew();
            page.addAnnotation(annot);
            // at this position.
            CDSRectangle rect = new CDSRectangle(50, 500, 500, 550);
            annot.setRectangle(rect);
            // with this look & feel
            // attention: with some acrobat versions the look & feel,
            // even conform to the spec, may not be honored!
            PDBorderStyle bs = (PDBorderStyle) PDBorderStyle.META.createNew();
            bs.setWidth(4);
            // bug with Acrobat 7.0, must explicitly state default
            bs.setStyle(COSName.create("S"));
            annot.setBorderStyle(bs);
            annot.setColor(new float[] { 0.5f, 0.5f, 0.5f });
            annot.setHighlightingMode(COSName.create("O"));
            // and this action
            PDAction action = PDActionJavaScript.createNew("app.alert('hello')");
            annot.setAction(action);
    

    An appropriate action may be created like this

     PDActionGoTo actionGoTo = (PDActionGoTo) PDActionGoTo.META.createNew();
     COSArray destination = COSArray.create();
     destination.add(page.cosGetObject());
     destination.add(PDExplicitDestination.CN_DISPLAY_MODE_Fit);
     actionGoTo.cosGetDict().put(CN_D, destination);
    

    Michael