How do I generate some text, which links forward to an other page in the pdf file I am generating?
I have the code below which generate working pdf links, bit it require that the page I link to, exists in the pdf file at the time I generate the link. Is there any way to avoid this problem?
My use case is that I am generating the table of content, which is in the beginning of the pdf file, but it need to link to the content pages, which don't yet exists when I generate the table of content.
int linkToPdfPage=42;
PdfArray array = new PdfArray();
array.add(pdfDocument.getPage(linkToPdfPage).getPdfObject());
array.add(PdfName.Fit);
PdfDestination dest2 = PdfDestination.makeDestination(array);
Link newLink=new Link("Link text", PdfAction.createGoTo(dest2));
newLink.getLinkAnnotation().setBorder(new PdfArray(new int[]{0,0,0}));