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
-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.
Get Certified Today * Register for a JBoss Training Course
Free Certification Exam for All Training Attendees Through End of 2005
Visit http://www.jboss.com/services/certification for more information
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions