2014-05-02 8 views
0

J'essaye d'ajouter l'ancre (destinations nommées) au pdf utilisant l'api itext java. Mais ça ne marche pas. Quand je clique sur le texte, rien ne se passe. C'est ce que je fais.Ajouter l'ancre au pdf using itext java

Anchor anchor = 
      new Anchor("Jump down to next paragraph"); 
    anchor.setReference("#linkTarget"); 
    Paragraph paragraph = new Paragraph(); 
    paragraph.add(anchor); 
    document.add(paragraph); 

    Anchor anchorTarget = 
      new Anchor("This is the target of the link above"); 
    anchor.setName("linkTarget"); 
    Paragraph targetParagraph = new Paragraph(); 
    targetParagraph.setSpacingBefore(50); 

    targetParagraph.add(anchorTarget); 
    document.add(targetParagraph); 

Qu'est-ce que je fais mal ?. Toute aide

Répondre

1

Essayez ceci. Cela a fonctionné pour moi. setLocalGoto() et setLocalDestination() feront la magie.

Chunk chunk = new Chunk("Contact information"); 
    chunk.setLocalGoto("contact"); 
    document.add(new Paragraph(chunk)); 
    document.newPage(); 

    chunk chunk1 = new Chunk("Contact information"); 
    chunk1.setLocalDestination("contact"); 
    Chapter chapter = new Chapter(new Paragraph(chunk1),1);  
    chapter.setNumberDepth(0); 
    document.add(chapter);