Page 1 of 1

How to generate a Table of Contents?

Posted: Mon Mar 15, 2010 7:42 pm
by allanj42
I am generating a compound document with several sections and I require a Table of Contents (TOC) with the starting page number of each section. I generate each section as a RichViewEdit (RVE) then append the sections together into an overall RVE.

Currently, I am making note of the length in pages of each section and adding them up as I generate my report. This only works as long as each section starts on a new page. However, I want to allow my user to flow one section into the next without a page break.

I'm guessing that the way to do the TOC is to insert Checkpoints before appending each section to the overall RVE, then visit each Checkpoint (without actually displaying them - how?) and make note of the current page number (how to determine?) for each section. Finally, re-build the entire report, with the correct page numbers in the TOC.

If this is the right approach, then my questions are:
1. How to "visit" each checkpoint without displaying them (OnCheckpointVisible is not supported in RVE, according to the Help file)?
2. How to determine the current page number where each checkpoint lands?

Thanks,
Jeff Allan

Posted: Mon Mar 15, 2010 8:27 pm
by Sergey Tkachenko
First, I suggest using headings instead of checkpoints.
Next, TOC for TRichViewEdit can be built only after formatting document in RVPrint (or RVReportHelper, if you use it for printing).
Next, in version 12, you can use RVPrint.GetFirstItemOnPage to find which item starts a given page, so you can find a page for the given heading item. However, this function
a) not very convenient for this task
b) does not allow to find page numbers, if heading is inside table cell.

In the latest version of TRichView, there is much more convenient function RVPrint.GetPageNo, returning page number for the given position on the document. It is introduced in version 12.2 beta, available for registered users.
I can make an example for building TOC using this function, it will be posted in the protected section of this forum (I opened access for you)

Posted: Thu Mar 18, 2010 6:09 pm
by Sergey Tkachenko
An example for creating a table of contents is added in the protected section of the forums (protected forum "Examples, Demos").

In this example, page numbers in TOC are added as a plain text (no updating after editing).

The demo works for RichView+RVPrint (cannot be used in ScaleRichView that has its own pagination procedure, different from RVPrint).