[Unit] Adding a table of contents
-
- Site Admin
- Posts: 17557
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
In DOC/RTF file, PAGEREF is a reference to a bookmark. When generating TOC, MS Word adds a hidden auto-maintained bookmark before each heading.
I can add checkpoints before each heading when generating TOC. However, they will not be hidden or auto-maintained, they will be like any other checkpoints. If it's ok, I'll make an example.
I can add checkpoints before each heading when generating TOC. However, they will not be hidden or auto-maintained, they will be like any other checkpoints. If it's ok, I'll make an example.
Sergey,
Thank you for taking the time to review my question. I already have added checkpoints (bookmarks) before each heading. However the difficult part for me is to update the TOC generation so that the page number displayed is a reference to those bookmarks and not a static page number, when exported to RTF. An example would be very welcome.
John.
Thank you for taking the time to review my question. I already have added checkpoints (bookmarks) before each heading. However the difficult part for me is to update the TOC generation so that the page number displayed is a reference to those bookmarks and not a static page number, when exported to RTF. An example would be very welcome.
John.
-
- Site Admin
- Posts: 17557
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
This unit contains code for generation TOC for RTF:
Differences:
- new functions add checkpoints before each heading in the document;
- new functions insert RTF fields "PAGEREF" in place of page numbers.
There are 2 main ways for insertion RTF codes using TRichView:
1) using text with a style having rvteoRTFCode in Options;
2) using some control and processing OnSaveComponentToFile.
This example uses the first method. Its disadvantage: in TRichView, you can see all these codes directly in text.
The functions still require formatted document, because they calculate page numbers that will be displayed in MS Word when you load this document initially. You still need to select TOC paragraphs in Word and press F9 to update page numbers.
The code for calculating initial values of page numbers could be removed (they can be displayed initially, as, for example, '?'), it would simplify the code.
Update:
2018-Apr-18: for compatibility with TRichView 17.3; the margins problem in the RVReportHelper version is fixed.
Old version:
http://www.trichview.com/support/files/rvtocrtf.zip - for TRichView 17.2 and older
It contains the same functions as the original version, with the same parameters.Differences:
- new functions add checkpoints before each heading in the document;
- new functions insert RTF fields "PAGEREF" in place of page numbers.
There are 2 main ways for insertion RTF codes using TRichView:
1) using text with a style having rvteoRTFCode in Options;
2) using some control and processing OnSaveComponentToFile.
This example uses the first method. Its disadvantage: in TRichView, you can see all these codes directly in text.
The functions still require formatted document, because they calculate page numbers that will be displayed in MS Word when you load this document initially. You still need to select TOC paragraphs in Word and press F9 to update page numbers.
The code for calculating initial values of page numbers could be removed (they can be displayed initially, as, for example, '?'), it would simplify the code.
Update:
2018-Apr-18: for compatibility with TRichView 17.3; the margins problem in the RVReportHelper version is fixed.
Old version:
http://www.trichview.com/support/files/rvtocrtf.zip - for TRichView 17.2 and older
-
- Posts: 4
- Joined: Wed Nov 21, 2012 3:24 pm
Small problem in TOC generation
The number of pages of the Table of Contents is not correctly calculated IF
- the margins of the RichView are greater than the default margins AND
- there is a TOC line which is just a bit too large to fit in 1 line AND
- because of this line we need a 2nd page for the TOC
Obviously, the RichView used to build the TOC thinks that the TOC fits in 1 page while it needs 2 pages in fact.
It works with this change in function AddTableOfContents (TRVReportHelper overload):
// building TOC in RVReportHelper2, calculating TOCPageCount
RVReportHelper2.RichView.Style := RVReportHelper.RichView.Style;
ADD-> RVReportHelper2.RichView.LeftMargin := RVReportHelper.RichView.LeftMargin;
ADD-> RVReportHelper2.RichView.RightMargin := RVReportHelper.RichView.RightMargin;
RVReportHelper2.RichView.AddNL(Title, TitleStyleNo, TitleParaNo);
Kind regards,
Hans
- the margins of the RichView are greater than the default margins AND
- there is a TOC line which is just a bit too large to fit in 1 line AND
- because of this line we need a 2nd page for the TOC
Obviously, the RichView used to build the TOC thinks that the TOC fits in 1 page while it needs 2 pages in fact.
It works with this change in function AddTableOfContents (TRVReportHelper overload):
// building TOC in RVReportHelper2, calculating TOCPageCount
RVReportHelper2.RichView.Style := RVReportHelper.RichView.Style;
ADD-> RVReportHelper2.RichView.LeftMargin := RVReportHelper.RichView.LeftMargin;
ADD-> RVReportHelper2.RichView.RightMargin := RVReportHelper.RichView.RightMargin;
RVReportHelper2.RichView.AddNL(Title, TitleStyleNo, TitleParaNo);
Kind regards,
Hans
-
- Site Admin
- Posts: 17557
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
-
- Site Admin
- Posts: 17557
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: [Unit] Adding a table of contents
I updated the demos for compatibility with TRichView 17.3
Here is a brief overview of available "table of context demo projects":
1. Adding TOC in TRichView, pages are calculated according to TRVPrint settings. Alternatively, adding TOC in TRVReportHelper, using the specified PageWidth and PageHeight: http://www.trichview.com/forums/viewtop ... 787#p15121
How to use: http://www.trichview.com/forums/viewtop ... 122#p15122
2. Adding TOC containing RTF codes in place of page numbers. If you save this document in RTF, open in MS Word and update fields, references to pages will be added in these places: http://www.trichview.com/forums/viewtop ... 373#p20373 (before updating fields, MS Word will display page numbers calculated by TRichView).
This unit is used exactly like the previous unit.
3. A special item type that does not build a TOC itself, but, if exported to RTF or DocX, inserts a TOC code. When MS Word updates this field, it builds a TOC itself. This item was initially introduced here: http://www.trichview.com/forums/viewtop ... f=3&t=7034 , but now it is included in TRichView unit as <TRichView Dir>\TRichView\Source\RVTOCItem.pas.
Like any other non-text object, it is inserted using AddItem or InsertItem methods.
Since this item does not build TOC itself but simply generates RTF/DocX code, it is universal, you can insert it in TRichView, TRVReportHelper or in a ScaleRichView editor.
4. ScaleRichView version of TOC is in <TRichView Dir>\SRVControls\Demos\DocViewer\
Initially, it was almost an exact copy of #1, it just calculated page numbers in TSRichViewEdit. But in one of recent updates, we added new features:
- TOC items may be hyperlinks
- TOC may be built without page numbers
(for example, hypertext TOC is useful for HTML export)
Here is a brief overview of available "table of context demo projects":
1. Adding TOC in TRichView, pages are calculated according to TRVPrint settings. Alternatively, adding TOC in TRVReportHelper, using the specified PageWidth and PageHeight: http://www.trichview.com/forums/viewtop ... 787#p15121
How to use: http://www.trichview.com/forums/viewtop ... 122#p15122
2. Adding TOC containing RTF codes in place of page numbers. If you save this document in RTF, open in MS Word and update fields, references to pages will be added in these places: http://www.trichview.com/forums/viewtop ... 373#p20373 (before updating fields, MS Word will display page numbers calculated by TRichView).
This unit is used exactly like the previous unit.
3. A special item type that does not build a TOC itself, but, if exported to RTF or DocX, inserts a TOC code. When MS Word updates this field, it builds a TOC itself. This item was initially introduced here: http://www.trichview.com/forums/viewtop ... f=3&t=7034 , but now it is included in TRichView unit as <TRichView Dir>\TRichView\Source\RVTOCItem.pas.
Like any other non-text object, it is inserted using AddItem or InsertItem methods.
Since this item does not build TOC itself but simply generates RTF/DocX code, it is universal, you can insert it in TRichView, TRVReportHelper or in a ScaleRichView editor.
4. ScaleRichView version of TOC is in <TRichView Dir>\SRVControls\Demos\DocViewer\
Initially, it was almost an exact copy of #1, it just calculated page numbers in TSRichViewEdit. But in one of recent updates, we added new features:
- TOC items may be hyperlinks
- TOC may be built without page numbers
(for example, hypertext TOC is useful for HTML export)