The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

marce (1) [Avatar] Offline

I create a document pdf with iText, it's a great tool and i thank you for made it free, but I need to make an Index based on the location of the content.

I put the page number in the page on the even onEndPage, that was the easy part, the hard part and i don't know how to do it, is an index at the beginning of the document.

In the console output i can print the page number in which each part of the content is going to appear with this function: writer.getPageNumber()

The only problem is how to refresh the content of the index of the document if this was added before of knowing the position of the content parts.

I read in the api documentation about IndexEvents but there isn't an example to see how it works.

Thanks for your valuable help.

Message was edited by:
blowagie (284) [Avatar] Offline
Re: Numbered Index
Section 14.1.3 deals with reordering pages.
Basically there are two approaches:

(1) You create the PDF without the page numbers, then create a new PDF in a second pass (PdfStamper), adding new pages at the beginning of the document with insertPage, stamping the page numbers on all the following pages.
(2) Create the document as you are doing, add the index at the end with a different page numbering (i, ii, iii, iv instead of 1, 2, 3, 4), then reorder the pages so that the index comes first.