Bruno Lowagie <bruno <at> lowagie.com> writes: > > Jason Frank wrote: > > >Bruno Lowagie <bruno <at> lowagie.com> writes: > > > > > >>There is more than one way to do this. > >>For a large report, I would write the content to one file and the ToC to > >>another one. Afterwards, you can concatenate both files. > >>br, > >>Bruno > >> > >> > >> > > > >I have two follow-up questions about making a table of contents (ToC), using > >the suggested approach of two separate documents then concatenated together. > > > >1. As I'm building the ToC and the content, I won't know how many pages the > >ToC will eventually take up. This means I can't fill in the proper page > >number next to each ToC entry until after I'm done, because the ToC goes ahead > >of the content in the concatenated document and thus all my page numbers have > >to be offset by the number of pages in the ToC. What's the best way to go > >back and fill these in? Clearly I could make a "dummy" ToC, count how many > >pages it was, then make the "real" ToC using that information, but there must > >be a better way. > > > >2. Is there any way to make the entries in the ToC act as hyperlinks to the > >relevant page in the content, when I concatenate the two documents? > > > In your actual document, you should add bookmarks: > http://itextdocs.lowagie.com/tutorial/objects/bookmarks/#bookmarks > > Create the ToC twice. > Once without references/pagenumbers, so that you know the number of > pages needed. > Throw away this ToC and generate it a second time. > You can use SimpleBookmark.getBookmark(reader); to retrieve the > bookmarks you added in the actual document. They contain sufficient info > to get a page number (augment it with the number of pages in the ToC) > and to retrieve info on the destination of the hyperlink. > > You'll have to do some puzzle work to get all the necessary pieces, but > it's possible. > br, > Bruno >
I understand the idea, but I can't figure out one piece of the puzzle. When I'm creating the ToC for the second time, I can easily figure out the correct page number to put next to each ToC entry, based on the SimpleBookmarks that I retrieved earlier from my main document and on the number of pages in the ToC (as you suggest). But at that time, the destinations that I'd like to associate with the ToC entries do not exist in the ToC document -- they are for pages that I'm going to append later. How can I make each ToC entry point to a destination that does not exist yet? Maybe this is possible, but I don't know how to do it. Thanks for the help. ------------------------------------------------------- SF.Net email is sponsored by: Tame your development challenges with Apache's Geronimo App Server. Download it for free - -and be entered to win a 42" plasma tv or your very own Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php _______________________________________________ iText-questions mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/itext-questions
