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