Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3661678
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:19:55+00:00 2026-05-19T01:19:55+00:00

I’m trying to create a simple table of contents (the document is only 4

  • 0

I’m trying to create a simple table of contents (the document is only 4 pages long).
The issue I have is that while my mouse does turn into a hand, when I click it nothing happens.
And yes the targets are on another page.

creation of a table of contents line:

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

One of the targets:

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);

The Goto String matches with the Anchor name so I don’t see what I’m doing wrong.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T01:19:55+00:00Added an answer on May 19, 2026 at 1:19 am

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

    Another approach would be to use Chunks for both the link and the destination.

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

    My reading of PdfDocument (localGoto and localDestination) leads me to believe that the order in which they’re created doesn’t matter… wait… Nope, shouldn’t matter so long as both are actually called.

    Have you actually stepped through your code to be sure they’re both Actually Called?

    Another option: End run. Drop down to the PDF-native code and do it there. Build your own PdfDestination for the chapter location and PdfAction for the TOC. Something like this:

    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);
    

    NOTES:

    1. You can reuse a given PdfAction if you need multiple links to the same spot.
    2. There are many ways to define a PdfDestination, I just used the one I prefer. YMMV.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I have a text area in my form which accepts all possible characters from
I have a reasonable size flat file database of text documents mostly saved in
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am writing an app with both english and french support. The app requests
I'm parsing an XML file, the creators of it stuck in a bunch social
I am using Paperclip to handle profile photo uploads in my app. They upload

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.