Worst case should be two passes. Pass #1: Build everything but the TOC. Pass #2: INSERT N pages with PdfStamper.insertPage( int, Rectangle ), and build link annotations. Rather than building the links yourself, an instance of ColumnText might do the trick where its static methods might not.
You'll probably want to use a "PdfPageLabels" to number the TOC pages i, ii, iii... and the remaining pages 1, 2, 3... That way the page numbers written into your TOC are correct and you don't need to worry about N TOC pages throwing everything off. If you can calculate how many TOC entries you have, you should be able to predetermine the number of pages you have, but that could require two passes over your data rather than over the PDFs... Could be an improvement, might not. Only you can know that. --Mark Storer Senior Software Engineer Cardiff.com import legalese.Disclaimer; Disclaimer<Cardiff> DisCard = null; > -----Original Message----- > From: M. Niedermair [mailto:[email protected]] > Sent: Tuesday, March 08, 2011 9:06 AM > To: Post all your questions about iText here > Subject: Re: [iText-questions] TOC with iText > > Hi, > > > First pass: > > * Reserve space for the table of contents on a blank page > > the problem is, that I dont know at the beginnig, how many > pages I need for the TOC. > > > * Create an ArrayList of objects containing text and page numbers > > * Add objects to the ArrayList as I encounter "interesting" content > > that should be added to the TOC > > * Finalize the document > > > > Second pass: > > * Use PdfStamper to add the TOC content to the existing > PDF, in the blank space I reserved in the first pass. > > Can I use internal gotos a la PDFAction.gotoLocalPage() or a > Anchor with a imported page from PdfStamper? > > Do you use "table of figure", index, ... > > In the worst case, I must use three passes to finish the document. > > Thanks > Michael > > > -------------------------------------------------------------- > ---------------- > What You Don't Know About Data Connectivity CAN Hurt You This > paper provides an overview of data connectivity, details its > effect on application quality, and explores various > alternative solutions. http://p.sf.net/sfu/progress-d2d > _______________________________________________ > iText-questions mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/itext-questions > > iText(R) is a registered trademark of 1T3XT BVBA. > Many questions posted to this list can (and will) be answered > with a reference to the iText book: > http://www.itextpdf.com/book/ Please check the keywords list > before you ask for examples: http://itextpdf.com/themes/keywords.php > > ------------------------------------------------------------------------------ What You Don't Know About Data Connectivity CAN Hurt You This paper provides an overview of data connectivity, details its effect on application quality, and explores various alternative solutions. http://p.sf.net/sfu/progress-d2d _______________________________________________ iText-questions mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/itext-questions iText(R) is a registered trademark of 1T3XT BVBA. Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/ Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php
