IText has problems with Anchors (available for click, but nothing happens)

I am trying to create a simple table of contents (a document lasts only 4 pages). The problem is that although my mouse turns into a hand, when I click it, nothing happens. And yes, the goals are on another page.

creating a table of contents line:

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

One of the goals:

Anchor anchor = new Anchor("Contact information", font1);
anchor.setName("Contact information");
Chapter chapter = new Chapter(new Paragraph(anchor), 1);    
chapter.setNumberDepth(0);
document.add(chapter);

Goto Stringconsistent Anchor name, so I donโ€™t see what I am doing wrong.

+5
source share
2 answers

In this example from iText in action, the internal link uses #the name.

Another approach would be to use Chunkboth for reference and for the recipient.

chunkDest.setLocalDesitination("foo");
...
chunkLink.setLocalGoto("foo"); // or "#foo"?

PdfDocument (localGoto localDestination) , , , ... ... , , .

, , ?

: . PDF . PdfDestination PdfAction TOC. - :

PdfDestination fitH = new PdfDestination(PdfDestination.FITH);
// the destination doesn't have a page associated with it until you call
//  gotoLocalPage.  Kinda goofy, but we can work with it.
PdfAction link = PdfAction.gotoLocalPage(pageNum, fitH, writer);
chunk.setAction(link);

:

  • PdfAction, .
  • PdfDestination, , . YMMV.
+1

: ftp://ns.tnet.dp.ua/pub/ORACLE/Developers/Java_Doc_LIB/PDFLib/iText/tutorial/ch03.html, , "#" + { }.

:

Anchor anchor1 = new Anchor("This is an internal link");
anchor1.setName("link1");
Anchor anchor2 = new Anchor("Click here to jump to the internal link");
anchor.setReference("#link1"); 
0

All Articles