0

I'm using IText to generate a pdf for my project. Using help from this How to generate a Table of Contents "TOC" with iText?, I was able to generate a pdf with TOC. However I'm unable to figure out how can I navigate to a page when page number is clicked. I tried adding action inside the pdf template but that doesn't seem to work. Thanks in advance for your help.

This is what I've added to the answer already given in the linked question:

 final PdfTemplate template2 = this.tocPlaceholder.get("Test");
        template2.beginText();
        template2.setFontAndSize(baseFont, 12);
        template2.setTextMatrix(50 - this.baseFont.getWidthPoint(String.valueOf(writer.getPageNumber()), 12), 0);
        template2.showText(String.valueOf(writer.getPageNumber()));
        PdfAction action = PdfAction.gotoLocalPage(writer.getPageNumber(),new PdfDestination(0),writer);
        template2.setAction(action , 0,0,0,0);
    template2.endText();
piqueblinders
  • 99
  • 1
  • 10
  • you can reload the pdf and set the default page, but no idea about the redirect page. – EAS Mar 28 '22 at 11:19
  • Hi, can you attach a minimal reproducible code sample? Right now when one tries to run your code, they will get undefined references to `baseFont`, `writer` etc. Also, have you tried iText 7? It has better capabilities to handle TOCs – Alexey Subach Apr 04 '22 at 09:35

0 Answers0